blob: c2376d42a749cbe99fec40e5c146a2e5ef1312f9 [file] [log] [blame]
reed@android.coma0bd7f42009-08-03 17:22:46 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2009 The Android Open Source Project
reed@android.coma0bd7f42009-08-03 17:22:46 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.coma0bd7f42009-08-03 17:22:46 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
reed@android.coma0bd7f42009-08-03 17:22:46 +00009#include "SkBitmapProcState.h"
reed@android.com6123e472009-08-04 01:52:27 +000010#include "SkColorPriv.h"
reed@google.com87bde7d2013-07-22 17:44:54 +000011#include "SkPaint.h"
tomhudson@google.com26a4d352012-09-04 16:25:27 +000012#include "SkTypes.h"
reed@android.com6123e472009-08-04 01:52:27 +000013#include "SkUtils.h"
commit-bot@chromium.org5abacf62013-07-30 13:16:18 +000014#include "SkUtilsArm.h"
15
16#include "SkConvolver.h"
reed@android.coma0bd7f42009-08-03 17:22:46 +000017
commit-bot@chromium.org6f2d4d42014-04-02 15:03:56 +000018#if !defined(SK_CPU_ARM64) && SK_ARM_ARCH >= 6 && !defined(SK_CPU_BENDIAN)
vandebo@chromium.orgdb8b51c2011-05-03 02:23:11 +000019void SI8_D16_nofilter_DX_arm(
20 const SkBitmapProcState& s,
21 const uint32_t* SK_RESTRICT xy,
22 int count,
digit@google.com536079b2012-08-28 15:22:37 +000023 uint16_t* SK_RESTRICT colors) SK_ATTRIBUTE_OPTIMIZE_O1;
vandebo@chromium.orgdb8b51c2011-05-03 02:23:11 +000024
reed@android.coma0bd7f42009-08-03 17:22:46 +000025void SI8_D16_nofilter_DX_arm(const SkBitmapProcState& s,
26 const uint32_t* SK_RESTRICT xy,
27 int count, uint16_t* SK_RESTRICT colors) {
28 SkASSERT(count > 0 && colors != NULL);
29 SkASSERT(s.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask));
reed@google.comeb3fe8e2013-07-22 17:26:19 +000030 SkASSERT(SkPaint::kNone_FilterLevel == s.fFilterLevel);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000031
reed@android.coma0bd7f42009-08-03 17:22:46 +000032 const uint16_t* SK_RESTRICT table = s.fBitmap->getColorTable()->lock16BitCache();
33 const uint8_t* SK_RESTRICT srcAddr = (const uint8_t*)s.fBitmap->getPixels();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000034
reed@android.coma0bd7f42009-08-03 17:22:46 +000035 // buffer is y32, x16, x16, x16, x16, x16
36 // bump srcAddr to the proper row, since we're told Y never changes
37 SkASSERT((unsigned)xy[0] < (unsigned)s.fBitmap->height());
38 srcAddr = (const uint8_t*)((const char*)srcAddr +
39 xy[0] * s.fBitmap->rowBytes());
rmistry@google.comfbfcd562012-08-23 18:09:54 +000040
reed@android.coma0bd7f42009-08-03 17:22:46 +000041 uint8_t src;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000042
reed@android.coma0bd7f42009-08-03 17:22:46 +000043 if (1 == s.fBitmap->width()) {
44 src = srcAddr[0];
45 uint16_t dstValue = table[src];
46 sk_memset16(colors, dstValue, count);
47 } else {
48 int i;
49 int count8 = count >> 3;
50 const uint16_t* SK_RESTRICT xx = (const uint16_t*)(xy + 1);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000051
reed@android.coma0bd7f42009-08-03 17:22:46 +000052 asm volatile (
commit-bot@chromium.orgc5180842013-11-07 15:57:32 +000053 "cmp %[count8], #0 \n\t" // compare loop counter with 0
54 "beq 2f \n\t" // if loop counter == 0, exit
55 "1: \n\t"
56 "ldmia %[xx]!, {r5, r7, r9, r11} \n\t" // load ptrs to pixels 0-7
57 "subs %[count8], %[count8], #1 \n\t" // decrement loop counter
58 "uxth r4, r5 \n\t" // extract ptr 0
59 "mov r5, r5, lsr #16 \n\t" // extract ptr 1
60 "uxth r6, r7 \n\t" // extract ptr 2
61 "mov r7, r7, lsr #16 \n\t" // extract ptr 3
62 "ldrb r4, [%[srcAddr], r4] \n\t" // load pixel 0 from image
63 "uxth r8, r9 \n\t" // extract ptr 4
64 "ldrb r5, [%[srcAddr], r5] \n\t" // load pixel 1 from image
65 "mov r9, r9, lsr #16 \n\t" // extract ptr 5
66 "ldrb r6, [%[srcAddr], r6] \n\t" // load pixel 2 from image
67 "uxth r10, r11 \n\t" // extract ptr 6
68 "ldrb r7, [%[srcAddr], r7] \n\t" // load pixel 3 from image
69 "mov r11, r11, lsr #16 \n\t" // extract ptr 7
70 "ldrb r8, [%[srcAddr], r8] \n\t" // load pixel 4 from image
71 "add r4, r4, r4 \n\t" // double pixel 0 for RGB565 lookup
72 "ldrb r9, [%[srcAddr], r9] \n\t" // load pixel 5 from image
73 "add r5, r5, r5 \n\t" // double pixel 1 for RGB565 lookup
74 "ldrb r10, [%[srcAddr], r10] \n\t" // load pixel 6 from image
75 "add r6, r6, r6 \n\t" // double pixel 2 for RGB565 lookup
76 "ldrb r11, [%[srcAddr], r11] \n\t" // load pixel 7 from image
77 "add r7, r7, r7 \n\t" // double pixel 3 for RGB565 lookup
78 "ldrh r4, [%[table], r4] \n\t" // load pixel 0 RGB565 from colmap
79 "add r8, r8, r8 \n\t" // double pixel 4 for RGB565 lookup
80 "ldrh r5, [%[table], r5] \n\t" // load pixel 1 RGB565 from colmap
81 "add r9, r9, r9 \n\t" // double pixel 5 for RGB565 lookup
82 "ldrh r6, [%[table], r6] \n\t" // load pixel 2 RGB565 from colmap
83 "add r10, r10, r10 \n\t" // double pixel 6 for RGB565 lookup
84 "ldrh r7, [%[table], r7] \n\t" // load pixel 3 RGB565 from colmap
85 "add r11, r11, r11 \n\t" // double pixel 7 for RGB565 lookup
86 "ldrh r8, [%[table], r8] \n\t" // load pixel 4 RGB565 from colmap
87 "ldrh r9, [%[table], r9] \n\t" // load pixel 5 RGB565 from colmap
88 "ldrh r10, [%[table], r10] \n\t" // load pixel 6 RGB565 from colmap
89 "ldrh r11, [%[table], r11] \n\t" // load pixel 7 RGB565 from colmap
90 "pkhbt r5, r4, r5, lsl #16 \n\t" // pack pixels 0 and 1
91 "pkhbt r6, r6, r7, lsl #16 \n\t" // pack pixels 2 and 3
92 "pkhbt r8, r8, r9, lsl #16 \n\t" // pack pixels 4 and 5
93 "pkhbt r10, r10, r11, lsl #16 \n\t" // pack pixels 6 and 7
94 "stmia %[colors]!, {r5, r6, r8, r10} \n\t" // store last 8 pixels
95 "bgt 1b \n\t" // loop if counter > 0
96 "2: \n\t"
97 : [xx] "+r" (xx), [count8] "+r" (count8), [colors] "+r" (colors)
98 : [table] "r" (table), [srcAddr] "r" (srcAddr)
99 : "memory", "cc", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11"
100 );
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000101
reed@android.coma0bd7f42009-08-03 17:22:46 +0000102 for (i = (count & 7); i > 0; --i) {
103 src = srcAddr[*xx++]; *colors++ = table[src];
104 }
105 }
reed@android.com6123e472009-08-04 01:52:27 +0000106
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000107 s.fBitmap->getColorTable()->unlock16BitCache();
reed@android.coma0bd7f42009-08-03 17:22:46 +0000108}
109
vandebo@chromium.orgdb8b51c2011-05-03 02:23:11 +0000110void SI8_opaque_D32_nofilter_DX_arm(
111 const SkBitmapProcState& s,
112 const uint32_t* SK_RESTRICT xy,
113 int count,
digit@google.com536079b2012-08-28 15:22:37 +0000114 SkPMColor* SK_RESTRICT colors) SK_ATTRIBUTE_OPTIMIZE_O1;
vandebo@chromium.orgdb8b51c2011-05-03 02:23:11 +0000115
reed@android.coma0bd7f42009-08-03 17:22:46 +0000116void SI8_opaque_D32_nofilter_DX_arm(const SkBitmapProcState& s,
117 const uint32_t* SK_RESTRICT xy,
118 int count, SkPMColor* SK_RESTRICT colors) {
119 SkASSERT(count > 0 && colors != NULL);
120 SkASSERT(s.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask));
reed@google.comeb3fe8e2013-07-22 17:26:19 +0000121 SkASSERT(SkPaint::kNone_FilterLevel == s.fFilterLevel);
reed@android.com6123e472009-08-04 01:52:27 +0000122
reed@android.coma0bd7f42009-08-03 17:22:46 +0000123 const SkPMColor* SK_RESTRICT table = s.fBitmap->getColorTable()->lockColors();
124 const uint8_t* SK_RESTRICT srcAddr = (const uint8_t*)s.fBitmap->getPixels();
reed@android.com6123e472009-08-04 01:52:27 +0000125
reed@android.coma0bd7f42009-08-03 17:22:46 +0000126 // buffer is y32, x16, x16, x16, x16, x16
127 // bump srcAddr to the proper row, since we're told Y never changes
128 SkASSERT((unsigned)xy[0] < (unsigned)s.fBitmap->height());
129 srcAddr = (const uint8_t*)((const char*)srcAddr + xy[0] * s.fBitmap->rowBytes());
reed@android.com6123e472009-08-04 01:52:27 +0000130
reed@android.coma0bd7f42009-08-03 17:22:46 +0000131 if (1 == s.fBitmap->width()) {
132 uint8_t src = srcAddr[0];
133 SkPMColor dstValue = table[src];
134 sk_memset32(colors, dstValue, count);
135 } else {
136 const uint16_t* xx = (const uint16_t*)(xy + 1);
reed@android.com6123e472009-08-04 01:52:27 +0000137
reed@android.coma0bd7f42009-08-03 17:22:46 +0000138 asm volatile (
commit-bot@chromium.orgc5180842013-11-07 15:57:32 +0000139 "subs %[count], %[count], #8 \n\t" // decrement count by 8, set flags
140 "blt 2f \n\t" // if count < 0, branch to singles
141 "1: \n\t" // eights loop
142 "ldmia %[xx]!, {r5, r7, r9, r11} \n\t" // load ptrs to pixels 0-7
143 "uxth r4, r5 \n\t" // extract ptr 0
144 "mov r5, r5, lsr #16 \n\t" // extract ptr 1
145 "uxth r6, r7 \n\t" // extract ptr 2
146 "mov r7, r7, lsr #16 \n\t" // extract ptr 3
147 "ldrb r4, [%[srcAddr], r4] \n\t" // load pixel 0 from image
148 "uxth r8, r9 \n\t" // extract ptr 4
149 "ldrb r5, [%[srcAddr], r5] \n\t" // load pixel 1 from image
150 "mov r9, r9, lsr #16 \n\t" // extract ptr 5
151 "ldrb r6, [%[srcAddr], r6] \n\t" // load pixel 2 from image
152 "uxth r10, r11 \n\t" // extract ptr 6
153 "ldrb r7, [%[srcAddr], r7] \n\t" // load pixel 3 from image
154 "mov r11, r11, lsr #16 \n\t" // extract ptr 7
155 "ldrb r8, [%[srcAddr], r8] \n\t" // load pixel 4 from image
156 "ldrb r9, [%[srcAddr], r9] \n\t" // load pixel 5 from image
157 "ldrb r10, [%[srcAddr], r10] \n\t" // load pixel 6 from image
158 "ldrb r11, [%[srcAddr], r11] \n\t" // load pixel 7 from image
159 "ldr r4, [%[table], r4, lsl #2] \n\t" // load pixel 0 SkPMColor from colmap
160 "ldr r5, [%[table], r5, lsl #2] \n\t" // load pixel 1 SkPMColor from colmap
161 "ldr r6, [%[table], r6, lsl #2] \n\t" // load pixel 2 SkPMColor from colmap
162 "ldr r7, [%[table], r7, lsl #2] \n\t" // load pixel 3 SkPMColor from colmap
163 "ldr r8, [%[table], r8, lsl #2] \n\t" // load pixel 4 SkPMColor from colmap
164 "ldr r9, [%[table], r9, lsl #2] \n\t" // load pixel 5 SkPMColor from colmap
165 "ldr r10, [%[table], r10, lsl #2] \n\t" // load pixel 6 SkPMColor from colmap
166 "ldr r11, [%[table], r11, lsl #2] \n\t" // load pixel 7 SkPMColor from colmap
167 "subs %[count], %[count], #8 \n\t" // decrement loop counter
168 "stmia %[colors]!, {r4-r11} \n\t" // store 8 pixels
169 "bge 1b \n\t" // loop if counter >= 0
170 "2: \n\t"
171 "adds %[count], %[count], #8 \n\t" // fix up counter, set flags
172 "beq 4f \n\t" // if count == 0, branch to exit
173 "3: \n\t" // singles loop
174 "ldrh r4, [%[xx]], #2 \n\t" // load pixel ptr
175 "subs %[count], %[count], #1 \n\t" // decrement loop counter
176 "ldrb r5, [%[srcAddr], r4] \n\t" // load pixel from image
177 "ldr r6, [%[table], r5, lsl #2] \n\t" // load SkPMColor from colmap
178 "str r6, [%[colors]], #4 \n\t" // store pixel, update ptr
179 "bne 3b \n\t" // loop if counter != 0
180 "4: \n\t" // exit
181 : [xx] "+r" (xx), [count] "+r" (count), [colors] "+r" (colors)
182 : [table] "r" (table), [srcAddr] "r" (srcAddr)
183 : "memory", "cc", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11"
184 );
reed@android.coma0bd7f42009-08-03 17:22:46 +0000185 }
reed@android.com6123e472009-08-04 01:52:27 +0000186
reed@google.com0a6151d2013-10-10 14:44:56 +0000187 s.fBitmap->getColorTable()->unlockColors();
reed@android.coma0bd7f42009-08-03 17:22:46 +0000188}
commit-bot@chromium.org6f2d4d42014-04-02 15:03:56 +0000189#endif // !defined(SK_CPU_ARM64) && SK_ARM_ARCH >= 6 && !defined(SK_CPU_BENDIAN)
reed@android.coma0bd7f42009-08-03 17:22:46 +0000190
reed@android.coma0bd7f42009-08-03 17:22:46 +0000191///////////////////////////////////////////////////////////////////////////////
192
reed@android.com6123e472009-08-04 01:52:27 +0000193/* If we replace a sampleproc, then we null-out the associated shaderproc,
194 otherwise the shader won't even look at the matrix/sampler
195 */
reed@android.coma0bd7f42009-08-03 17:22:46 +0000196void SkBitmapProcState::platformProcs() {
commit-bot@chromium.org6f2d4d42014-04-02 15:03:56 +0000197#if !defined(SK_CPU_ARM64) && SK_ARM_ARCH >= 6 && !defined(SK_CPU_BENDIAN)
reed@android.coma0bd7f42009-08-03 17:22:46 +0000198 bool isOpaque = 256 == fAlphaScale;
199 bool justDx = false;
200
201 if (fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) {
202 justDx = true;
203 }
204
205 switch (fBitmap->config()) {
reed@android.coma0bd7f42009-08-03 17:22:46 +0000206 case SkBitmap::kIndex8_Config:
reed@google.comb4a57f82013-07-22 17:33:43 +0000207 if (justDx && SkPaint::kNone_FilterLevel == fFilterLevel) {
reed@android.com6123e472009-08-04 01:52:27 +0000208#if 0 /* crashing on android device */
reed@android.coma0bd7f42009-08-03 17:22:46 +0000209 fSampleProc16 = SI8_D16_nofilter_DX_arm;
reed@android.com6123e472009-08-04 01:52:27 +0000210 fShaderProc16 = NULL;
211#endif
reed@android.coma0bd7f42009-08-03 17:22:46 +0000212 if (isOpaque) {
reed@android.com152f7482009-08-07 19:14:34 +0000213 // this one is only very slighty faster than the C version
reed@android.coma0bd7f42009-08-03 17:22:46 +0000214 fSampleProc32 = SI8_opaque_D32_nofilter_DX_arm;
reed@android.com6123e472009-08-04 01:52:27 +0000215 fShaderProc32 = NULL;
reed@android.coma0bd7f42009-08-03 17:22:46 +0000216 }
217 }
reed@android.com152f7482009-08-07 19:14:34 +0000218 break;
reed@android.coma0bd7f42009-08-03 17:22:46 +0000219 default:
220 break;
221 }
commit-bot@chromium.org6f2d4d42014-04-02 15:03:56 +0000222#endif
reed@android.coma0bd7f42009-08-03 17:22:46 +0000223}
humper@google.com16acf752013-07-19 21:12:08 +0000224
commit-bot@chromium.orgc5180842013-11-07 15:57:32 +0000225///////////////////////////////////////////////////////////////////////////////
commit-bot@chromium.org5abacf62013-07-30 13:16:18 +0000226
commit-bot@chromium.orgc5180842013-11-07 15:57:32 +0000227extern void platformConvolutionProcs_arm_neon(SkConvolutionProcs* procs);
commit-bot@chromium.org5abacf62013-07-30 13:16:18 +0000228
commit-bot@chromium.orgc5180842013-11-07 15:57:32 +0000229void platformConvolutionProcs_arm(SkConvolutionProcs* procs) {
commit-bot@chromium.org5abacf62013-07-30 13:16:18 +0000230}
231
reed@google.comfed04b32013-09-05 20:31:17 +0000232void SkBitmapProcState::platformConvolutionProcs(SkConvolutionProcs* procs) {
commit-bot@chromium.orgc5180842013-11-07 15:57:32 +0000233 SK_ARM_NEON_WRAP(platformConvolutionProcs_arm)(procs);
skia.committer@gmail.com1f3c7382013-07-20 07:00:58 +0000234}