1#ifndef MUPDF_FITZ_IMP_H
2#define MUPDF_FITZ_IMP_H
3
4#include "mupdf/fitz.h"
5
6#include <stdio.h>
7
8struct 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
17void fz_new_colorspace_context(fz_context *ctx);
18fz_colorspace_context *fz_keep_colorspace_context(fz_context *ctx);
19void fz_drop_colorspace_context(fz_context *ctx);
20
21void fz_new_font_context(fz_context *ctx);
22
23fz_font_context *fz_keep_font_context(fz_context *ctx);
24void fz_drop_font_context(fz_context *ctx);
25
26struct 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
35void fz_default_image_decode(void *arg, int w, int h, int l2factor, fz_irect *subarea);
36int fz_default_image_scale(void *arg, int dst_w, int dst_h, int src_w, int src_h);
37
38fz_context *fz_clone_context_internal(fz_context *ctx);
39
40void fz_init_aa_context(fz_context *ctx);
41
42void fz_new_glyph_cache_context(fz_context *ctx);
43fz_glyph_cache *fz_keep_glyph_cache(fz_context *ctx);
44void fz_drop_glyph_cache_context(fz_context *ctx);
45
46void fz_new_document_handler_context(fz_context *ctx);
47void fz_drop_document_handler_context(fz_context *ctx);
48fz_document_handler_context *fz_keep_document_handler_context(fz_context *ctx);
49
50fz_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
58void fz_assert_lock_held(fz_context *ctx, int lock);
59void fz_assert_lock_not_held(fz_context *ctx, int lock);
60void fz_lock_debug_lock(fz_context *ctx, int lock);
61void 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
72static inline void
73fz_lock(fz_context *ctx, int lock)
74{
75 fz_lock_debug_lock(ctx, lock);
76 ctx->locks.lock(ctx->locks.user, lock);
77}
78
79static inline void
80fz_unlock(fz_context *ctx, int lock)
81{
82 fz_lock_debug_unlock(ctx, lock);
83 ctx->locks.unlock(ctx->locks.user, lock);
84}
85
86static inline void *
87fz_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
103static inline void *
104fz_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
120static inline void *
121fz_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
137static inline int
138fz_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
158static inline int
159fz_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
179static inline int
180fz_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