• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 
9 #include "SkBitmapProcState.h"
10 #include "SkBitmapScaler.h"
11 #include "SkColorPriv.h"
12 #include "SkPaint.h"
13 #include "SkUtils.h"
14 
SI8_opaque_D32_nofilter_DX_mips_dsp(const SkBitmapProcState & s,const uint32_t * SK_RESTRICT xy,int count,SkPMColor * SK_RESTRICT colors)15 static void SI8_opaque_D32_nofilter_DX_mips_dsp(const SkBitmapProcState& s,
16                                                 const uint32_t* SK_RESTRICT xy,
17                                                 int count, SkPMColor* SK_RESTRICT colors) {
18     SkASSERT(count > 0 && colors != nullptr);
19     SkASSERT(s.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask));
20     SkASSERT(kNone_SkFilterQuality == s.fFilterLevel);
21     const SkPMColor* SK_RESTRICT table = s.fPixmap.ctable()->readColors();
22     const uint8_t* SK_RESTRICT srcAddr = (const uint8_t*)s.fPixmap.addr();
23     srcAddr = (const uint8_t*)((const char*)srcAddr + xy[0] * s.fPixmap.rowBytes());
24 
25     if (1 == s.fPixmap.width()) {
26         uint8_t src = srcAddr[0];
27         SkPMColor dstValue = table[src];
28         sk_memset32(colors, dstValue, count);
29     } else {
30         const uint16_t* xx = (const uint16_t*)(xy + 1);
31         int s0, s1, s2, s3, s4, s5, s6, s7;
32         __asm__ volatile (
33             ".set    push                                \n\t"
34             ".set    noreorder                           \n\t"
35             ".set    noat                                \n\t"
36             "srl     $t8,       %[count],    4           \n\t"
37             "beqz    $t8,       3f                       \n\t"
38             " nop                                        \n\t"
39         "1:                                              \n\t"
40             "addiu   $t8,       $t8,         -1          \n\t"
41             "beqz    $t8,       2f                       \n\t"
42             " addiu  %[count],  %[count],    -16         \n\t"
43             "pref    0,         32(%[xx])                \n\t"
44             "lhu     $t0,       0(%[xx])                 \n\t"
45             "lhu     $t1,       2(%[xx])                 \n\t"
46             "lhu     $t2,       4(%[xx])                 \n\t"
47             "lhu     $t3,       6(%[xx])                 \n\t"
48             "lhu     $t4,       8(%[xx])                 \n\t"
49             "lhu     $t5,       10(%[xx])                \n\t"
50             "lhu     $t6,       12(%[xx])                \n\t"
51             "lhu     $t7,       14(%[xx])                \n\t"
52             "lhu     %[s0],     16(%[xx])                \n\t"
53             "lhu     %[s1],     18(%[xx])                \n\t"
54             "lhu     %[s2],     20(%[xx])                \n\t"
55             "lhu     %[s3],     22(%[xx])                \n\t"
56             "lhu     %[s4],     24(%[xx])                \n\t"
57             "lhu     %[s5],     26(%[xx])                \n\t"
58             "lhu     %[s6],     28(%[xx])                \n\t"
59             "lhu     %[s7],     30(%[xx])                \n\t"
60             "lbux    $t0,       $t0(%[srcAddr])          \n\t"
61             "lbux    $t1,       $t1(%[srcAddr])          \n\t"
62             "lbux    $t2,       $t2(%[srcAddr])          \n\t"
63             "lbux    $t3,       $t3(%[srcAddr])          \n\t"
64             "lbux    $t4,       $t4(%[srcAddr])          \n\t"
65             "lbux    $t5,       $t5(%[srcAddr])          \n\t"
66             "lbux    $t6,       $t6(%[srcAddr])          \n\t"
67             "lbux    $t7,       $t7(%[srcAddr])          \n\t"
68             "lbux    %[s0],     %[s0](%[srcAddr])        \n\t"
69             "lbux    %[s1],     %[s1](%[srcAddr])        \n\t"
70             "lbux    %[s2],     %[s2](%[srcAddr])        \n\t"
71             "lbux    %[s3],     %[s3](%[srcAddr])        \n\t"
72             "lbux    %[s4],     %[s4](%[srcAddr])        \n\t"
73             "lbux    %[s5],     %[s5](%[srcAddr])        \n\t"
74             "lbux    %[s6],     %[s6](%[srcAddr])        \n\t"
75             "lbux    %[s7],     %[s7](%[srcAddr])        \n\t"
76             "sll     $t0,       $t0,         2           \n\t"
77             "sll     $t1,       $t1,         2           \n\t"
78             "sll     $t2,       $t2,         2           \n\t"
79             "sll     $t3,       $t3,         2           \n\t"
80             "sll     $t4,       $t4,         2           \n\t"
81             "sll     $t5,       $t5,         2           \n\t"
82             "sll     $t6,       $t6,         2           \n\t"
83             "sll     $t7,       $t7,         2           \n\t"
84             "sll     %[s0],     %[s0],       2           \n\t"
85             "sll     %[s1],     %[s1],       2           \n\t"
86             "sll     %[s2],     %[s2],       2           \n\t"
87             "sll     %[s3],     %[s3],       2           \n\t"
88             "sll     %[s4],     %[s4],       2           \n\t"
89             "sll     %[s5],     %[s5],       2           \n\t"
90             "sll     %[s6],     %[s6],       2           \n\t"
91             "sll     %[s7],     %[s7],       2           \n\t"
92             "pref    0,         64(%[table])             \n\t"
93             "lwx     $t0,       $t0(%[table])            \n\t"
94             "lwx     $t1,       $t1(%[table])            \n\t"
95             "lwx     $t2,       $t2(%[table])            \n\t"
96             "lwx     $t3,       $t3(%[table])            \n\t"
97             "lwx     $t4,       $t4(%[table])            \n\t"
98             "lwx     $t5,       $t5(%[table])            \n\t"
99             "lwx     $t6,       $t6(%[table])            \n\t"
100             "lwx     $t7,       $t7(%[table])            \n\t"
101             "lwx     %[s0],     %[s0](%[table])          \n\t"
102             "lwx     %[s1],     %[s1](%[table])          \n\t"
103             "lwx     %[s2],     %[s2](%[table])          \n\t"
104             "lwx     %[s3],     %[s3](%[table])          \n\t"
105             "lwx     %[s4],     %[s4](%[table])          \n\t"
106             "lwx     %[s5],     %[s5](%[table])          \n\t"
107             "lwx     %[s6],     %[s6](%[table])          \n\t"
108             "lwx     %[s7],     %[s7](%[table])          \n\t"
109             "pref    30,        64(%[colors])            \n\t"
110             "sw      $t0,       0(%[colors])             \n\t"
111             "sw      $t1,       4(%[colors])             \n\t"
112             "sw      $t2,       8(%[colors])             \n\t"
113             "sw      $t3,       12(%[colors])            \n\t"
114             "sw      $t4,       16(%[colors])            \n\t"
115             "sw      $t5,       20(%[colors])            \n\t"
116             "sw      $t6,       24(%[colors])            \n\t"
117             "sw      $t7,       28(%[colors])            \n\t"
118             "sw      %[s0],     32(%[colors])            \n\t"
119             "sw      %[s1],     36(%[colors])            \n\t"
120             "sw      %[s2],     40(%[colors])            \n\t"
121             "sw      %[s3],     44(%[colors])            \n\t"
122             "sw      %[s4],     48(%[colors])            \n\t"
123             "sw      %[s5],     52(%[colors])            \n\t"
124             "sw      %[s6],     56(%[colors])            \n\t"
125             "sw      %[s7],     60(%[colors])            \n\t"
126             "addiu   %[xx],     %[xx],       32          \n\t"
127             "b       1b                                  \n\t"
128             " addiu  %[colors], %[colors],   64          \n\t"
129         "2:                                              \n\t"
130             "lhu     $t0,       0(%[xx])                 \n\t"
131             "lhu     $t1,       2(%[xx])                 \n\t"
132             "lhu     $t2,       4(%[xx])                 \n\t"
133             "lhu     $t3,       6(%[xx])                 \n\t"
134             "lhu     $t4,       8(%[xx])                 \n\t"
135             "lhu     $t5,       10(%[xx])                \n\t"
136             "lhu     $t6,       12(%[xx])                \n\t"
137             "lhu     $t7,       14(%[xx])                \n\t"
138             "lhu     %[s0],     16(%[xx])                \n\t"
139             "lhu     %[s1],     18(%[xx])                \n\t"
140             "lhu     %[s2],     20(%[xx])                \n\t"
141             "lhu     %[s3],     22(%[xx])                \n\t"
142             "lhu     %[s4],     24(%[xx])                \n\t"
143             "lhu     %[s5],     26(%[xx])                \n\t"
144             "lhu     %[s6],     28(%[xx])                \n\t"
145             "lhu     %[s7],     30(%[xx])                \n\t"
146             "lbux    $t0,       $t0(%[srcAddr])          \n\t"
147             "lbux    $t1,       $t1(%[srcAddr])          \n\t"
148             "lbux    $t2,       $t2(%[srcAddr])          \n\t"
149             "lbux    $t3,       $t3(%[srcAddr])          \n\t"
150             "lbux    $t4,       $t4(%[srcAddr])          \n\t"
151             "lbux    $t5,       $t5(%[srcAddr])          \n\t"
152             "lbux    $t6,       $t6(%[srcAddr])          \n\t"
153             "lbux    $t7,       $t7(%[srcAddr])          \n\t"
154             "lbux    %[s0],     %[s0](%[srcAddr])        \n\t"
155             "lbux    %[s1],     %[s1](%[srcAddr])        \n\t"
156             "lbux    %[s2],     %[s2](%[srcAddr])        \n\t"
157             "lbux    %[s3],     %[s3](%[srcAddr])        \n\t"
158             "lbux    %[s4],     %[s4](%[srcAddr])        \n\t"
159             "lbux    %[s5],     %[s5](%[srcAddr])        \n\t"
160             "lbux    %[s6],     %[s6](%[srcAddr])        \n\t"
161             "lbux    %[s7],     %[s7](%[srcAddr])        \n\t"
162             "sll     $t0,       $t0,         2           \n\t"
163             "sll     $t1,       $t1,         2           \n\t"
164             "sll     $t2,       $t2,         2           \n\t"
165             "sll     $t3,       $t3,         2           \n\t"
166             "sll     $t4,       $t4,         2           \n\t"
167             "sll     $t5,       $t5,         2           \n\t"
168             "sll     $t6,       $t6,         2           \n\t"
169             "sll     $t7,       $t7,         2           \n\t"
170             "sll     %[s0],     %[s0],       2           \n\t"
171             "sll     %[s1],     %[s1],       2           \n\t"
172             "sll     %[s2],     %[s2],       2           \n\t"
173             "sll     %[s3],     %[s3],       2           \n\t"
174             "sll     %[s4],     %[s4],       2           \n\t"
175             "sll     %[s5],     %[s5],       2           \n\t"
176             "sll     %[s6],     %[s6],       2           \n\t"
177             "sll     %[s7],     %[s7],       2           \n\t"
178             "lwx     $t0,       $t0(%[table])            \n\t"
179             "lwx     $t1,       $t1(%[table])            \n\t"
180             "lwx     $t2,       $t2(%[table])            \n\t"
181             "lwx     $t3,       $t3(%[table])            \n\t"
182             "lwx     $t4,       $t4(%[table])            \n\t"
183             "lwx     $t5,       $t5(%[table])            \n\t"
184             "lwx     $t6,       $t6(%[table])            \n\t"
185             "lwx     $t7,       $t7(%[table])            \n\t"
186             "lwx     %[s0],     %[s0](%[table])          \n\t"
187             "lwx     %[s1],     %[s1](%[table])          \n\t"
188             "lwx     %[s2],     %[s2](%[table])          \n\t"
189             "lwx     %[s3],     %[s3](%[table])          \n\t"
190             "lwx     %[s4],     %[s4](%[table])          \n\t"
191             "lwx     %[s5],     %[s5](%[table])          \n\t"
192             "lwx     %[s6],     %[s6](%[table])          \n\t"
193             "lwx     %[s7],     %[s7](%[table])          \n\t"
194             "sw      $t0,       0(%[colors])             \n\t"
195             "sw      $t1,       4(%[colors])             \n\t"
196             "sw      $t2,       8(%[colors])             \n\t"
197             "sw      $t3,       12(%[colors])            \n\t"
198             "sw      $t4,       16(%[colors])            \n\t"
199             "sw      $t5,       20(%[colors])            \n\t"
200             "sw      $t6,       24(%[colors])            \n\t"
201             "sw      $t7,       28(%[colors])            \n\t"
202             "sw      %[s0],     32(%[colors])            \n\t"
203             "sw      %[s1],     36(%[colors])            \n\t"
204             "sw      %[s2],     40(%[colors])            \n\t"
205             "sw      %[s3],     44(%[colors])            \n\t"
206             "sw      %[s4],     48(%[colors])            \n\t"
207             "sw      %[s5],     52(%[colors])            \n\t"
208             "sw      %[s6],     56(%[colors])            \n\t"
209             "sw      %[s7],     60(%[colors])            \n\t"
210             "addiu   %[xx],     %[xx],       32          \n\t"
211             "beqz    %[count],  4f                       \n\t"
212             " addiu  %[colors], %[colors],   64          \n\t"
213         "3:                                              \n\t"
214             "addiu   %[count],  %[count],    -1          \n\t"
215             "lhu     $t0,       0(%[xx])                 \n\t"
216             "lbux    $t1,       $t0(%[srcAddr])          \n\t"
217             "sll     $t1,       $t1,         2           \n\t"
218             "lwx     $t2,       $t1(%[table])            \n\t"
219             "sw      $t2,       0(%[colors])             \n\t"
220             "addiu   %[xx],     %[xx],       2           \n\t"
221             "bnez    %[count],  3b                       \n\t"
222             " addiu  %[colors], %[colors],   4           \n\t"
223         "4:                                              \n\t"
224             ".set    pop                                 \n\t"
225             : [xx]"+r"(xx), [count]"+r"(count), [colors]"+r"(colors),
226               [s0]"=&r"(s0), [s1]"=&r"(s1), [s2]"=&r"(s2), [s3]"=&r"(s3),
227               [s4]"=&r"(s4), [s5]"=&r"(s5), [s6]"=&r"(s6), [s7]"=&r"(s7)
228             : [table]"r"(table), [srcAddr]"r"(srcAddr)
229             : "memory", "t0", "t1", "t2", "t3",
230               "t4", "t5", "t6", "t7", "t8"
231         );
232     }
233 }
234 
235 /*  If we replace a sampleproc, then we null-out the associated shaderproc,
236     otherwise the shader won't even look at the matrix/sampler
237  */
238 
platformProcs()239 void SkBitmapProcState::platformProcs() {
240     bool isOpaque = 256 == fAlphaScale;
241     bool justDx = false;
242 
243     if (fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) {
244         justDx = true;
245     }
246 
247     switch (fPixmap.colorType()) {
248         case kIndex_8_SkColorType:
249             if (justDx && kNone_SkFilterQuality == fFilterLevel) {
250                 if (isOpaque) {
251                     fSampleProc32 = SI8_opaque_D32_nofilter_DX_mips_dsp;
252                     fShaderProc32 = nullptr;
253                 }
254             }
255             break;
256         default:
257             break;
258     }
259 }
260 
PlatformConvolutionProcs(SkConvolutionProcs *)261 void SkBitmapScaler::PlatformConvolutionProcs(SkConvolutionProcs*) {}
262