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