| 1 | #ifndef MUPDF_FITZ_IMP_H | 
|---|
| 2 | #define MUPDF_FITZ_IMP_H | 
|---|
| 3 |  | 
|---|
| 4 | #include "mupdf/fitz.h" | 
|---|
| 5 |  | 
|---|
| 6 | #include <stdio.h> | 
|---|
| 7 |  | 
|---|
| 8 | struct fz_buffer_s | 
|---|
| 9 | { | 
|---|
| 10 | int refs; | 
|---|
| 11 | unsigned char *data; | 
|---|
| 12 | size_t cap, len; | 
|---|
| 13 | int unused_bits; | 
|---|
| 14 | int shared; | 
|---|
| 15 | }; | 
|---|
| 16 |  | 
|---|
| 17 | void fz_new_colorspace_context(fz_context *ctx); | 
|---|
| 18 | fz_colorspace_context *fz_keep_colorspace_context(fz_context *ctx); | 
|---|
| 19 | void fz_drop_colorspace_context(fz_context *ctx); | 
|---|
| 20 |  | 
|---|
| 21 | void fz_new_font_context(fz_context *ctx); | 
|---|
| 22 |  | 
|---|
| 23 | fz_font_context *fz_keep_font_context(fz_context *ctx); | 
|---|
| 24 | void fz_drop_font_context(fz_context *ctx); | 
|---|
| 25 |  | 
|---|
| 26 | struct fz_tuning_context_s | 
|---|
| 27 | { | 
|---|
| 28 | int refs; | 
|---|
| 29 | fz_tune_image_decode_fn *image_decode; | 
|---|
| 30 | void *image_decode_arg; | 
|---|
| 31 | fz_tune_image_scale_fn *image_scale; | 
|---|
| 32 | void *image_scale_arg; | 
|---|
| 33 | }; | 
|---|
| 34 |  | 
|---|
| 35 | void fz_default_image_decode(void *arg, int w, int h, int l2factor, fz_irect *subarea); | 
|---|
| 36 | int fz_default_image_scale(void *arg, int dst_w, int dst_h, int src_w, int src_h); | 
|---|
| 37 |  | 
|---|
| 38 | fz_context *fz_clone_context_internal(fz_context *ctx); | 
|---|
| 39 |  | 
|---|
| 40 | void fz_init_aa_context(fz_context *ctx); | 
|---|
| 41 |  | 
|---|
| 42 | void fz_new_glyph_cache_context(fz_context *ctx); | 
|---|
| 43 | fz_glyph_cache *fz_keep_glyph_cache(fz_context *ctx); | 
|---|
| 44 | void fz_drop_glyph_cache_context(fz_context *ctx); | 
|---|
| 45 |  | 
|---|
| 46 | void fz_new_document_handler_context(fz_context *ctx); | 
|---|
| 47 | void fz_drop_document_handler_context(fz_context *ctx); | 
|---|
| 48 | fz_document_handler_context *fz_keep_document_handler_context(fz_context *ctx); | 
|---|
| 49 |  | 
|---|
| 50 | fz_stream *fz_open_file_ptr_no_close(fz_context *ctx, FILE *file); | 
|---|
| 51 |  | 
|---|
| 52 | #if defined(MEMENTO) || !defined(NDEBUG) | 
|---|
| 53 | #define FITZ_DEBUG_LOCKING | 
|---|
| 54 | #endif | 
|---|
| 55 |  | 
|---|
| 56 | #ifdef FITZ_DEBUG_LOCKING | 
|---|
| 57 |  | 
|---|
| 58 | void fz_assert_lock_held(fz_context *ctx, int lock); | 
|---|
| 59 | void fz_assert_lock_not_held(fz_context *ctx, int lock); | 
|---|
| 60 | void fz_lock_debug_lock(fz_context *ctx, int lock); | 
|---|
| 61 | void fz_lock_debug_unlock(fz_context *ctx, int lock); | 
|---|
| 62 |  | 
|---|
| 63 | #else | 
|---|
| 64 |  | 
|---|
| 65 | #define fz_assert_lock_held(A,B) do { } while (0) | 
|---|
| 66 | #define fz_assert_lock_not_held(A,B) do { } while (0) | 
|---|
| 67 | #define fz_lock_debug_lock(A,B) do { } while (0) | 
|---|
| 68 | #define fz_lock_debug_unlock(A,B) do { } while (0) | 
|---|
| 69 |  | 
|---|
| 70 | #endif /* !FITZ_DEBUG_LOCKING */ | 
|---|
| 71 |  | 
|---|
| 72 | static inline void | 
|---|
| 73 | fz_lock(fz_context *ctx, int lock) | 
|---|
| 74 | { | 
|---|
| 75 | fz_lock_debug_lock(ctx, lock); | 
|---|
| 76 | ctx->locks.lock(ctx->locks.user, lock); | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | static inline void | 
|---|
| 80 | fz_unlock(fz_context *ctx, int lock) | 
|---|
| 81 | { | 
|---|
| 82 | fz_lock_debug_unlock(ctx, lock); | 
|---|
| 83 | ctx->locks.unlock(ctx->locks.user, lock); | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | static inline void * | 
|---|
| 87 | fz_keep_imp(fz_context *ctx, void *p, int *refs) | 
|---|
| 88 | { | 
|---|
| 89 | if (p) | 
|---|
| 90 | { | 
|---|
| 91 | (void)Memento_checkIntPointerOrNull(refs); | 
|---|
| 92 | fz_lock(ctx, FZ_LOCK_ALLOC); | 
|---|
| 93 | if (*refs > 0) | 
|---|
| 94 | { | 
|---|
| 95 | (void)Memento_takeRef(p); | 
|---|
| 96 | ++*refs; | 
|---|
| 97 | } | 
|---|
| 98 | fz_unlock(ctx, FZ_LOCK_ALLOC); | 
|---|
| 99 | } | 
|---|
| 100 | return p; | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | static inline void * | 
|---|
| 104 | fz_keep_imp8(fz_context *ctx, void *p, int8_t *refs) | 
|---|
| 105 | { | 
|---|
| 106 | if (p) | 
|---|
| 107 | { | 
|---|
| 108 | (void)Memento_checkBytePointerOrNull(refs); | 
|---|
| 109 | fz_lock(ctx, FZ_LOCK_ALLOC); | 
|---|
| 110 | if (*refs > 0) | 
|---|
| 111 | { | 
|---|
| 112 | (void)Memento_takeRef(p); | 
|---|
| 113 | ++*refs; | 
|---|
| 114 | } | 
|---|
| 115 | fz_unlock(ctx, FZ_LOCK_ALLOC); | 
|---|
| 116 | } | 
|---|
| 117 | return p; | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|
| 120 | static inline void * | 
|---|
| 121 | fz_keep_imp16(fz_context *ctx, void *p, int16_t *refs) | 
|---|
| 122 | { | 
|---|
| 123 | if (p) | 
|---|
| 124 | { | 
|---|
| 125 | (void)Memento_checkShortPointerOrNull(refs); | 
|---|
| 126 | fz_lock(ctx, FZ_LOCK_ALLOC); | 
|---|
| 127 | if (*refs > 0) | 
|---|
| 128 | { | 
|---|
| 129 | (void)Memento_takeRef(p); | 
|---|
| 130 | ++*refs; | 
|---|
| 131 | } | 
|---|
| 132 | fz_unlock(ctx, FZ_LOCK_ALLOC); | 
|---|
| 133 | } | 
|---|
| 134 | return p; | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | static inline int | 
|---|
| 138 | fz_drop_imp(fz_context *ctx, void *p, int *refs) | 
|---|
| 139 | { | 
|---|
| 140 | if (p) | 
|---|
| 141 | { | 
|---|
| 142 | int drop; | 
|---|
| 143 | (void)Memento_checkIntPointerOrNull(refs); | 
|---|
| 144 | fz_lock(ctx, FZ_LOCK_ALLOC); | 
|---|
| 145 | if (*refs > 0) | 
|---|
| 146 | { | 
|---|
| 147 | (void)Memento_dropIntRef(p); | 
|---|
| 148 | drop = --*refs == 0; | 
|---|
| 149 | } | 
|---|
| 150 | else | 
|---|
| 151 | drop = 0; | 
|---|
| 152 | fz_unlock(ctx, FZ_LOCK_ALLOC); | 
|---|
| 153 | return drop; | 
|---|
| 154 | } | 
|---|
| 155 | return 0; | 
|---|
| 156 | } | 
|---|
| 157 |  | 
|---|
| 158 | static inline int | 
|---|
| 159 | fz_drop_imp8(fz_context *ctx, void *p, int8_t *refs) | 
|---|
| 160 | { | 
|---|
| 161 | if (p) | 
|---|
| 162 | { | 
|---|
| 163 | int drop; | 
|---|
| 164 | (void)Memento_checkBytePointerOrNull(refs); | 
|---|
| 165 | fz_lock(ctx, FZ_LOCK_ALLOC); | 
|---|
| 166 | if (*refs > 0) | 
|---|
| 167 | { | 
|---|
| 168 | (void)Memento_dropByteRef(p); | 
|---|
| 169 | drop = --*refs == 0; | 
|---|
| 170 | } | 
|---|
| 171 | else | 
|---|
| 172 | drop = 0; | 
|---|
| 173 | fz_unlock(ctx, FZ_LOCK_ALLOC); | 
|---|
| 174 | return drop; | 
|---|
| 175 | } | 
|---|
| 176 | return 0; | 
|---|
| 177 | } | 
|---|
| 178 |  | 
|---|
| 179 | static inline int | 
|---|
| 180 | fz_drop_imp16(fz_context *ctx, void *p, int16_t *refs) | 
|---|
| 181 | { | 
|---|
| 182 | if (p) | 
|---|
| 183 | { | 
|---|
| 184 | int drop; | 
|---|
| 185 | (void)Memento_checkShortPointerOrNull(refs); | 
|---|
| 186 | fz_lock(ctx, FZ_LOCK_ALLOC); | 
|---|
| 187 | if (*refs > 0) | 
|---|
| 188 | { | 
|---|
| 189 | (void)Memento_dropShortRef(p); | 
|---|
| 190 | drop = --*refs == 0; | 
|---|
| 191 | } | 
|---|
| 192 | else | 
|---|
| 193 | drop = 0; | 
|---|
| 194 | fz_unlock(ctx, FZ_LOCK_ALLOC); | 
|---|
| 195 | return drop; | 
|---|
| 196 | } | 
|---|
| 197 | return 0; | 
|---|
| 198 | } | 
|---|
| 199 |  | 
|---|
| 200 | #endif | 
|---|
| 201 |  | 
|---|