summaryrefslogtreecommitdiffstats
path: root/gfx/cairo/pixman-bilinear-fastpath.patch
blob: b2c5f270cd21d08ca63795f5eac87a3e12a075ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
changeset:   94061:73a9b24d863a
tag:         bilin
tag:         qbase
tag:         qtip
tag:         tip
user:        Jeff Muizelaar <jmuizelaar@mozilla.com>
date:        Tue May 15 18:26:16 2012 -0400
summary:     Bug 754364. Add bilinear non-repeat and repeat fast paths. r=joe

diff --git a/gfx/cairo/libpixman/src/pixman-fast-path.c b/gfx/cairo/libpixman/src/pixman-fast-path.c
--- a/gfx/cairo/libpixman/src/pixman-fast-path.c
+++ b/gfx/cairo/libpixman/src/pixman-fast-path.c
@@ -1186,16 +1186,228 @@ FAST_NEAREST (8888_565_none, 8888, 0565,
 FAST_NEAREST (8888_565_pad, 8888, 0565, uint32_t, uint16_t, SRC, PAD)
 FAST_NEAREST (8888_565_normal, 8888, 0565, uint32_t, uint16_t, SRC, NORMAL)
 FAST_NEAREST (565_565_normal, 0565, 0565, uint16_t, uint16_t, SRC, NORMAL)
 FAST_NEAREST (8888_565_cover, 8888, 0565, uint32_t, uint16_t, OVER, COVER)
 FAST_NEAREST (8888_565_none, 8888, 0565, uint32_t, uint16_t, OVER, NONE)
 FAST_NEAREST (8888_565_pad, 8888, 0565, uint32_t, uint16_t, OVER, PAD)
 FAST_NEAREST (8888_565_normal, 8888, 0565, uint32_t, uint16_t, OVER, NORMAL)
 
+static force_inline void
+scaled_bilinear_scanline_8888_565_OVER (uint16_t *       dst,
+                                        const uint32_t * mask,
+                                        const uint32_t * src_top,
+                                        const uint32_t * src_bottom,
+                                        int32_t          w,
+                                        int              wt,
+                                        int              wb,
+                                        pixman_fixed_t   vx,
+                                        pixman_fixed_t   unit_x,
+                                        pixman_fixed_t   max_vx,
+                                        pixman_bool_t    zero_src)
+{
+    while ((w -= 1) >= 0)
+    {
+	uint32_t tl = src_top [pixman_fixed_to_int (vx)];
+	uint32_t tr = src_top [pixman_fixed_to_int (vx) + 1];
+	uint32_t bl = src_bottom [pixman_fixed_to_int (vx)];
+	uint32_t br = src_bottom [pixman_fixed_to_int (vx) + 1];
+	uint32_t src, result;
+	uint16_t d;
+	d = *dst;
+	src = bilinear_interpolation (tl, tr,
+				      bl, br,
+				      interpolation_coord(vx),
+				      wb >> (8 - INTERPOLATION_PRECISION_BITS));
+	vx += unit_x;
+	result = over (src, CONVERT_0565_TO_0888 (d));
+	*dst++ = CONVERT_8888_TO_0565(result);
+    }
+}
+
+static force_inline void
+scaled_bilinear_scanline_8888_8888_OVER (uint32_t *       dst,
+                                         const uint32_t * mask,
+                                         const uint32_t * src_top,
+                                         const uint32_t * src_bottom,
+                                         int32_t          w,
+                                         int              wt,
+                                         int              wb,
+                                         pixman_fixed_t   vx,
+                                         pixman_fixed_t   unit_x,
+                                         pixman_fixed_t   max_vx,
+                                         pixman_bool_t    zero_src)
+{
+    while ((w -= 1) >= 0)
+    {
+	uint32_t tl = src_top [pixman_fixed_to_int (vx)];
+	uint32_t tr = src_top [pixman_fixed_to_int (vx) + 1];
+	uint32_t bl = src_bottom [pixman_fixed_to_int (vx)];
+	uint32_t br = src_bottom [pixman_fixed_to_int (vx) + 1];
+	uint32_t src;
+	uint32_t d;
+	uint32_t result;
+	d = *dst;
+	src = bilinear_interpolation (tl, tr,
+				      bl, br,
+				      interpolation_coord(vx),
+				      wb >> (8 - INTERPOLATION_PRECISION_BITS));
+	vx += unit_x;
+	*dst++ = over (src, d);
+    }
+}
+
+#if 1
+
+static force_inline void
+scaled_bilinear_scanline_565_565_SRC (uint16_t *       dst,
+				      const uint32_t * mask,
+				      const uint16_t * src_top,
+				      const uint16_t * src_bottom,
+				      int32_t          w,
+				      int              wt,
+				      int              wb,
+				      pixman_fixed_t   vx,
+				      pixman_fixed_t   unit_x,
+				      pixman_fixed_t   max_vx,
+				      pixman_bool_t    zero_src)
+{
+    while ((w -= 1) >= 0)
+    {
+	uint16_t tl = src_top [pixman_fixed_to_int (vx)];
+	uint16_t tr = src_top [pixman_fixed_to_int (vx) + 1];
+	uint16_t bl = src_bottom [pixman_fixed_to_int (vx)];
+	uint16_t br = src_bottom [pixman_fixed_to_int (vx) + 1];
+	uint32_t d;
+	d = bilinear_interpolation(CONVERT_0565_TO_8888(tl),
+				   CONVERT_0565_TO_8888(tr),
+				   CONVERT_0565_TO_8888(bl),
+				   CONVERT_0565_TO_8888(br),
+				   interpolation_coord(vx),
+				   wb >> (8 - INTERPOLATION_PRECISION_BITS));
+	vx += unit_x;
+	*dst++ = CONVERT_8888_TO_0565(d);
+    }
+}
+
+#else
+
+#define SK_G16_MASK_IN_PLACE 0xfc0
+
+static inline uint32_t SkExpand_rgb_16(uint16_t c) {
+
+    return ((c & SK_G16_MASK_IN_PLACE) << 16) | (c & ~SK_G16_MASK_IN_PLACE);
+}
+
+/** Compress an expanded value (from SkExpand_rgb_16) back down to a 16bit
+    color value. The computation yields only 16bits of valid data, but we claim
+    to return 32bits, so that the compiler won't generate extra instructions to
+    "clean" the top 16bits. However, the top 16 can contain garbage, so it is
+    up to the caller to safely ignore them.
+*/
+static inline uint16_t SkCompact_rgb_16(uint32_t c) {
+    return ((c >> 16) & SK_G16_MASK_IN_PLACE) | (c & ~SK_G16_MASK_IN_PLACE);
+}
+// returns expanded * 5bits
+static inline uint32_t Filter_565_Expanded(unsigned x, unsigned y,
+                                           uint32_t a00, uint32_t a01,
+                                           uint32_t a10, uint32_t a11) {
+    a00 = SkExpand_rgb_16(a00);
+    a01 = SkExpand_rgb_16(a01);
+    a10 = SkExpand_rgb_16(a10);
+    a11 = SkExpand_rgb_16(a11);
+    
+    int xy = x * y >> 3;
+    return  a00 * (32 - 2*y - 2*x + xy) +
+            a01 * (2*x - xy) +
+            a10 * (2*y - xy) +
+            a11 * xy;
+}
+
+
+
+static force_inline void
+scaled_bilinear_scanline_565_565_SRC (uint16_t *       dst,
+				      const uint32_t * mask,
+				      const uint16_t * src_top,
+				      const uint16_t * src_bottom,
+				      int32_t          w,
+				      int              wt,
+				      int              wb,
+				      pixman_fixed_t   vx,
+				      pixman_fixed_t   unit_x,
+				      pixman_fixed_t   max_vx,
+				      pixman_bool_t    zero_src)
+{
+    while ((w -= 1) >= 0)
+    {
+	uint16_t tl = src_top [pixman_fixed_to_int (vx)];
+	uint16_t tr = src_top [pixman_fixed_to_int (vx) + 1];
+	uint16_t bl = src_bottom [pixman_fixed_to_int (vx)];
+	uint16_t br = src_bottom [pixman_fixed_to_int (vx) + 1];
+
+        uint32_t tmp = Filter_565_Expanded((vx>>12)&0xf, wb>>4, tl, tr, bl, br);
+        vx += unit_x;
+        *dst++ = SkCompact_rgb_16((tmp) >> 5);
+    }
+}
+
+
+#endif
+FAST_BILINEAR_MAINLOOP_COMMON (565_565_cover_SRC,
+			       scaled_bilinear_scanline_565_565_SRC,
+			       uint16_t, uint32_t, uint16_t,
+			       COVER, FLAG_NONE)
+FAST_BILINEAR_MAINLOOP_COMMON (565_565_pad_SRC,
+			       scaled_bilinear_scanline_565_565_SRC,
+			       uint16_t, uint32_t, uint16_t,
+			       PAD, FLAG_NONE)
+FAST_BILINEAR_MAINLOOP_COMMON (565_565_none_SRC,
+			       scaled_bilinear_scanline_565_565_SRC,
+			       uint16_t, uint32_t, uint16_t,
+			       NONE, FLAG_NONE)
+FAST_BILINEAR_MAINLOOP_COMMON (565_565_normal_SRC,
+			       scaled_bilinear_scanline_565_565_SRC,
+			       uint16_t, uint32_t, uint16_t,
+			       NORMAL, FLAG_NONE)
+
+FAST_BILINEAR_MAINLOOP_COMMON (8888_565_cover_OVER,
+			       scaled_bilinear_scanline_8888_565_OVER,
+			       uint32_t, uint32_t, uint16_t,
+			       COVER, FLAG_NONE)
+FAST_BILINEAR_MAINLOOP_COMMON (8888_565_pad_OVER,
+			       scaled_bilinear_scanline_8888_565_OVER,
+			       uint32_t, uint32_t, uint16_t,
+			       PAD, FLAG_NONE)
+FAST_BILINEAR_MAINLOOP_COMMON (8888_565_none_OVER,
+			       scaled_bilinear_scanline_8888_565_OVER,
+			       uint32_t, uint32_t, uint16_t,
+			       NONE, FLAG_NONE)
+FAST_BILINEAR_MAINLOOP_COMMON (8888_565_normal_OVER,
+			       scaled_bilinear_scanline_8888_565_OVER,
+			       uint32_t, uint32_t, uint16_t,
+			       NORMAL, FLAG_NONE)
+
+FAST_BILINEAR_MAINLOOP_COMMON (8888_8888_cover_OVER,
+			       scaled_bilinear_scanline_8888_8888_OVER,
+			       uint32_t, uint32_t, uint32_t,
+			       COVER, FLAG_NONE)
+FAST_BILINEAR_MAINLOOP_COMMON (8888_8888_pad_OVER,
+			       scaled_bilinear_scanline_8888_8888_OVER,
+			       uint32_t, uint32_t, uint32_t,
+			       PAD, FLAG_NONE)
+FAST_BILINEAR_MAINLOOP_COMMON (8888_8888_none_OVER,
+			       scaled_bilinear_scanline_8888_8888_OVER,
+			       uint32_t, uint32_t, uint32_t,
+			       NONE, FLAG_NONE)
+FAST_BILINEAR_MAINLOOP_COMMON (8888_8888_normal_OVER,
+			       scaled_bilinear_scanline_8888_8888_OVER,
+			       uint32_t, uint32_t, uint32_t,
+			       NORMAL, FLAG_NONE)
+
 #define REPEAT_MIN_WIDTH    32
 
 static void
 fast_composite_tiled_repeat (pixman_implementation_t *imp,
 			     pixman_composite_info_t *info)
 {
     PIXMAN_COMPOSITE_ARGS (info);
     pixman_composite_func_t func;
@@ -1960,16 +2172,20 @@ static const pixman_fast_path_t c_fast_p
 	PIXMAN_any,
 	(FAST_PATH_STANDARD_FLAGS | FAST_PATH_ID_TRANSFORM | FAST_PATH_BITS_IMAGE |
 	 FAST_PATH_NORMAL_REPEAT),
 	PIXMAN_any, 0,
 	PIXMAN_any, FAST_PATH_STD_DEST_FLAGS,
 	fast_composite_tiled_repeat
     },
 
+    SIMPLE_BILINEAR_FAST_PATH (SRC, r5g6b5, r5g6b5, 565_565),
+    SIMPLE_BILINEAR_FAST_PATH (OVER, a8r8g8b8, r5g6b5, 8888_565),
+    SIMPLE_BILINEAR_FAST_PATH (OVER, a8r8g8b8, a8r8g8b8, 8888_8888),
+
     {   PIXMAN_OP_NONE	},
 };
 
 #ifdef WORDS_BIGENDIAN
 #define A1_FILL_MASK(n, offs) (((1U << (n)) - 1) << (32 - (offs) - (n)))
 #else
 #define A1_FILL_MASK(n, offs) (((1U << (n)) - 1) << (offs))
 #endif
diff --git a/gfx/cairo/libpixman/src/pixman-inlines.h b/gfx/cairo/libpixman/src/pixman-inlines.h
--- a/gfx/cairo/libpixman/src/pixman-inlines.h
+++ b/gfx/cairo/libpixman/src/pixman-inlines.h
@@ -80,16 +80,21 @@ repeat (pixman_repeat_t repeat, int *c, 
     }
     return TRUE;
 }
 
 #ifdef MOZ_GFX_OPTIMIZE_MOBILE
 #define LOW_QUALITY_INTERPOLATION
 #endif
 
+#ifdef LOW_QUALITY_INTERPOLATION
+#define INTERPOLATION_PRECISION_BITS 4
+#else
+#define INTERPOLATION_PRECISION_BITS 8
+#endif
 static force_inline int32_t
 interpolation_coord(pixman_fixed_t t)
 {
 #ifdef LOW_QUALITY_INTERPOLATION
     return (t >> 12) & 0xf;
 #else
     return (t >> 8) & 0xff;
 #endif