• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2009 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 "SkColorPriv.h"
11 #include "SkTypes.h"
12 #include "SkUtils.h"
13 
14 #if SK_ARM_ARCH >= 6 && !defined(SK_CPU_BENDIAN)
15 void SI8_D16_nofilter_DX_arm(
16     const SkBitmapProcState& s,
17     const uint32_t* SK_RESTRICT xy,
18     int count,
19     uint16_t* SK_RESTRICT colors) SK_ATTRIBUTE_OPTIMIZE_O1;
20 
SI8_D16_nofilter_DX_arm(const SkBitmapProcState & s,const uint32_t * SK_RESTRICT xy,int count,uint16_t * SK_RESTRICT colors)21 void SI8_D16_nofilter_DX_arm(const SkBitmapProcState& s,
22                              const uint32_t* SK_RESTRICT xy,
23                              int count, uint16_t* SK_RESTRICT colors) {
24     SkASSERT(count > 0 && colors != NULL);
25     SkASSERT(s.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask));
26     SkASSERT(s.fDoFilter == false);
27 
28     const uint16_t* SK_RESTRICT table = s.fBitmap->getColorTable()->lock16BitCache();
29     const uint8_t* SK_RESTRICT srcAddr = (const uint8_t*)s.fBitmap->getPixels();
30 
31     // buffer is y32, x16, x16, x16, x16, x16
32     // bump srcAddr to the proper row, since we're told Y never changes
33     SkASSERT((unsigned)xy[0] < (unsigned)s.fBitmap->height());
34     srcAddr = (const uint8_t*)((const char*)srcAddr +
35                                xy[0] * s.fBitmap->rowBytes());
36 
37     uint8_t src;
38 
39     if (1 == s.fBitmap->width()) {
40         src = srcAddr[0];
41         uint16_t dstValue = table[src];
42         sk_memset16(colors, dstValue, count);
43     } else {
44         int i;
45         int count8 = count >> 3;
46         const uint16_t* SK_RESTRICT xx = (const uint16_t*)(xy + 1);
47 
48         asm volatile (
49                       "cmp        %[count8], #0                   \n\t"   // compare loop counter with 0
50                       "beq        2f                              \n\t"   // if loop counter == 0, exit
51                       "1:                                             \n\t"
52                       "ldmia      %[xx]!, {r5, r7, r9, r11}       \n\t"   // load ptrs to pixels 0-7
53                       "subs       %[count8], %[count8], #1        \n\t"   // decrement loop counter
54                       "uxth       r4, r5                          \n\t"   // extract ptr 0
55                       "mov        r5, r5, lsr #16                 \n\t"   // extract ptr 1
56                       "uxth       r6, r7                          \n\t"   // extract ptr 2
57                       "mov        r7, r7, lsr #16                 \n\t"   // extract ptr 3
58                       "ldrb       r4, [%[srcAddr], r4]            \n\t"   // load pixel 0 from image
59                       "uxth       r8, r9                          \n\t"   // extract ptr 4
60                       "ldrb       r5, [%[srcAddr], r5]            \n\t"   // load pixel 1 from image
61                       "mov        r9, r9, lsr #16                 \n\t"   // extract ptr 5
62                       "ldrb       r6, [%[srcAddr], r6]            \n\t"   // load pixel 2 from image
63                       "uxth       r10, r11                        \n\t"   // extract ptr 6
64                       "ldrb       r7, [%[srcAddr], r7]            \n\t"   // load pixel 3 from image
65                       "mov        r11, r11, lsr #16               \n\t"   // extract ptr 7
66                       "ldrb       r8, [%[srcAddr], r8]            \n\t"   // load pixel 4 from image
67                       "add        r4, r4, r4                      \n\t"   // double pixel 0 for RGB565 lookup
68                       "ldrb       r9, [%[srcAddr], r9]            \n\t"   // load pixel 5 from image
69                       "add        r5, r5, r5                      \n\t"   // double pixel 1 for RGB565 lookup
70                       "ldrb       r10, [%[srcAddr], r10]          \n\t"   // load pixel 6 from image
71                       "add        r6, r6, r6                      \n\t"   // double pixel 2 for RGB565 lookup
72                       "ldrb       r11, [%[srcAddr], r11]          \n\t"   // load pixel 7 from image
73                       "add        r7, r7, r7                      \n\t"   // double pixel 3 for RGB565 lookup
74                       "ldrh       r4, [%[table], r4]              \n\t"   // load pixel 0 RGB565 from colmap
75                       "add        r8, r8, r8                      \n\t"   // double pixel 4 for RGB565 lookup
76                       "ldrh       r5, [%[table], r5]              \n\t"   // load pixel 1 RGB565 from colmap
77                       "add        r9, r9, r9                      \n\t"   // double pixel 5 for RGB565 lookup
78                       "ldrh       r6, [%[table], r6]              \n\t"   // load pixel 2 RGB565 from colmap
79                       "add        r10, r10, r10                   \n\t"   // double pixel 6 for RGB565 lookup
80                       "ldrh       r7, [%[table], r7]              \n\t"   // load pixel 3 RGB565 from colmap
81                       "add        r11, r11, r11                   \n\t"   // double pixel 7 for RGB565 lookup
82                       "ldrh       r8, [%[table], r8]              \n\t"   // load pixel 4 RGB565 from colmap
83                       "ldrh       r9, [%[table], r9]              \n\t"   // load pixel 5 RGB565 from colmap
84                       "ldrh       r10, [%[table], r10]            \n\t"   // load pixel 6 RGB565 from colmap
85                       "ldrh       r11, [%[table], r11]            \n\t"   // load pixel 7 RGB565 from colmap
86                       "pkhbt      r5, r4, r5, lsl #16             \n\t"   // pack pixels 0 and 1
87                       "pkhbt      r6, r6, r7, lsl #16             \n\t"   // pack pixels 2 and 3
88                       "pkhbt      r8, r8, r9, lsl #16             \n\t"   // pack pixels 4 and 5
89                       "pkhbt      r10, r10, r11, lsl #16          \n\t"   // pack pixels 6 and 7
90                       "stmia      %[colors]!, {r5, r6, r8, r10}   \n\t"   // store last 8 pixels
91                       "bgt        1b                              \n\t"   // loop if counter > 0
92                       "2:                                             \n\t"
93                       : [xx] "+r" (xx), [count8] "+r" (count8), [colors] "+r" (colors)
94                       : [table] "r" (table), [srcAddr] "r" (srcAddr)
95                       : "memory", "cc", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11"
96                       );
97 
98         for (i = (count & 7); i > 0; --i) {
99             src = srcAddr[*xx++]; *colors++ = table[src];
100         }
101     }
102 
103     s.fBitmap->getColorTable()->unlock16BitCache();
104 }
105 
106 void SI8_opaque_D32_nofilter_DX_arm(
107     const SkBitmapProcState& s,
108     const uint32_t* SK_RESTRICT xy,
109     int count,
110     SkPMColor* SK_RESTRICT colors) SK_ATTRIBUTE_OPTIMIZE_O1;
111 
SI8_opaque_D32_nofilter_DX_arm(const SkBitmapProcState & s,const uint32_t * SK_RESTRICT xy,int count,SkPMColor * SK_RESTRICT colors)112 void SI8_opaque_D32_nofilter_DX_arm(const SkBitmapProcState& s,
113                                     const uint32_t* SK_RESTRICT xy,
114                                     int count, SkPMColor* SK_RESTRICT colors) {
115     SkASSERT(count > 0 && colors != NULL);
116     SkASSERT(s.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask));
117     SkASSERT(s.fDoFilter == false);
118 
119     const SkPMColor* SK_RESTRICT table = s.fBitmap->getColorTable()->lockColors();
120     const uint8_t* SK_RESTRICT srcAddr = (const uint8_t*)s.fBitmap->getPixels();
121 
122     // buffer is y32, x16, x16, x16, x16, x16
123     // bump srcAddr to the proper row, since we're told Y never changes
124     SkASSERT((unsigned)xy[0] < (unsigned)s.fBitmap->height());
125     srcAddr = (const uint8_t*)((const char*)srcAddr + xy[0] * s.fBitmap->rowBytes());
126 
127     if (1 == s.fBitmap->width()) {
128         uint8_t src = srcAddr[0];
129         SkPMColor dstValue = table[src];
130         sk_memset32(colors, dstValue, count);
131     } else {
132         const uint16_t* xx = (const uint16_t*)(xy + 1);
133 
134         asm volatile (
135                       "subs       %[count], %[count], #8          \n\t"   // decrement count by 8, set flags
136                       "blt        2f                              \n\t"   // if count < 0, branch to singles
137                       "1:                                             \n\t"   // eights loop
138                       "ldmia      %[xx]!, {r5, r7, r9, r11}       \n\t"   // load ptrs to pixels 0-7
139                       "uxth       r4, r5                          \n\t"   // extract ptr 0
140                       "mov        r5, r5, lsr #16                 \n\t"   // extract ptr 1
141                       "uxth       r6, r7                          \n\t"   // extract ptr 2
142                       "mov        r7, r7, lsr #16                 \n\t"   // extract ptr 3
143                       "ldrb       r4, [%[srcAddr], r4]            \n\t"   // load pixel 0 from image
144                       "uxth       r8, r9                          \n\t"   // extract ptr 4
145                       "ldrb       r5, [%[srcAddr], r5]            \n\t"   // load pixel 1 from image
146                       "mov        r9, r9, lsr #16                 \n\t"   // extract ptr 5
147                       "ldrb       r6, [%[srcAddr], r6]            \n\t"   // load pixel 2 from image
148                       "uxth       r10, r11                        \n\t"   // extract ptr 6
149                       "ldrb       r7, [%[srcAddr], r7]            \n\t"   // load pixel 3 from image
150                       "mov        r11, r11, lsr #16               \n\t"   // extract ptr 7
151                       "ldrb       r8, [%[srcAddr], r8]            \n\t"   // load pixel 4 from image
152                       "ldrb       r9, [%[srcAddr], r9]            \n\t"   // load pixel 5 from image
153                       "ldrb       r10, [%[srcAddr], r10]          \n\t"   // load pixel 6 from image
154                       "ldrb       r11, [%[srcAddr], r11]          \n\t"   // load pixel 7 from image
155                       "ldr        r4, [%[table], r4, lsl #2]      \n\t"   // load pixel 0 SkPMColor from colmap
156                       "ldr        r5, [%[table], r5, lsl #2]      \n\t"   // load pixel 1 SkPMColor from colmap
157                       "ldr        r6, [%[table], r6, lsl #2]      \n\t"   // load pixel 2 SkPMColor from colmap
158                       "ldr        r7, [%[table], r7, lsl #2]      \n\t"   // load pixel 3 SkPMColor from colmap
159                       "ldr        r8, [%[table], r8, lsl #2]      \n\t"   // load pixel 4 SkPMColor from colmap
160                       "ldr        r9, [%[table], r9, lsl #2]      \n\t"   // load pixel 5 SkPMColor from colmap
161                       "ldr        r10, [%[table], r10, lsl #2]    \n\t"   // load pixel 6 SkPMColor from colmap
162                       "ldr        r11, [%[table], r11, lsl #2]    \n\t"   // load pixel 7 SkPMColor from colmap
163                       "subs       %[count], %[count], #8          \n\t"   // decrement loop counter
164                       "stmia      %[colors]!, {r4-r11}            \n\t"   // store 8 pixels
165                       "bge        1b                              \n\t"   // loop if counter >= 0
166                       "2:                                             \n\t"
167                       "adds       %[count], %[count], #8          \n\t"   // fix up counter, set flags
168                       "beq        4f                              \n\t"   // if count == 0, branch to exit
169                       "3:                                             \n\t"   // singles loop
170                       "ldrh       r4, [%[xx]], #2                 \n\t"   // load pixel ptr
171                       "subs       %[count], %[count], #1          \n\t"   // decrement loop counter
172                       "ldrb       r5, [%[srcAddr], r4]            \n\t"   // load pixel from image
173                       "ldr        r6, [%[table], r5, lsl #2]      \n\t"   // load SkPMColor from colmap
174                       "str        r6, [%[colors]], #4             \n\t"   // store pixel, update ptr
175                       "bne        3b                              \n\t"   // loop if counter != 0
176                       "4:                                             \n\t"   // exit
177                       : [xx] "+r" (xx), [count] "+r" (count), [colors] "+r" (colors)
178                       : [table] "r" (table), [srcAddr] "r" (srcAddr)
179                       : "memory", "cc", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11"
180                       );
181     }
182 
183     s.fBitmap->getColorTable()->unlockColors(false);
184 }
185 #endif // SK_ARM_ARCH >= 6 && !defined(SK_CPU_BENDIAN)
186 
187 ///////////////////////////////////////////////////////////////////////////////
188 
189 /*  If we replace a sampleproc, then we null-out the associated shaderproc,
190     otherwise the shader won't even look at the matrix/sampler
191  */
platformProcs()192 void SkBitmapProcState::platformProcs() {
193     bool doFilter = fDoFilter;
194     bool isOpaque = 256 == fAlphaScale;
195     bool justDx = false;
196 
197     if (fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) {
198         justDx = true;
199     }
200 
201     switch (fBitmap->config()) {
202         case SkBitmap::kIndex8_Config:
203 #if SK_ARM_ARCH >= 6 && !defined(SK_CPU_BENDIAN)
204             if (justDx && !doFilter) {
205 #if 0   /* crashing on android device */
206                 fSampleProc16 = SI8_D16_nofilter_DX_arm;
207                 fShaderProc16 = NULL;
208 #endif
209                 if (isOpaque) {
210                     // this one is only very slighty faster than the C version
211                     fSampleProc32 = SI8_opaque_D32_nofilter_DX_arm;
212                     fShaderProc32 = NULL;
213                 }
214             }
215 #endif
216             break;
217         default:
218             break;
219     }
220 }
221