michael@0: /* michael@0: * Copyright 2009 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkBitmapProcState.h" michael@0: #include "SkColorPriv.h" michael@0: #include "SkPaint.h" michael@0: #include "SkTypes.h" michael@0: #include "SkUtils.h" michael@0: #include "SkUtilsArm.h" michael@0: michael@0: #include "SkConvolver.h" michael@0: michael@0: #if SK_ARM_ARCH >= 6 && !defined(SK_CPU_BENDIAN) michael@0: void SI8_D16_nofilter_DX_arm( michael@0: const SkBitmapProcState& s, michael@0: const uint32_t* SK_RESTRICT xy, michael@0: int count, michael@0: uint16_t* SK_RESTRICT colors) SK_ATTRIBUTE_OPTIMIZE_O1; michael@0: michael@0: void SI8_D16_nofilter_DX_arm(const SkBitmapProcState& s, michael@0: const uint32_t* SK_RESTRICT xy, michael@0: int count, uint16_t* SK_RESTRICT colors) { michael@0: SkASSERT(count > 0 && colors != NULL); michael@0: SkASSERT(s.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)); michael@0: SkASSERT(SkPaint::kNone_FilterLevel == s.fFilterLevel); michael@0: michael@0: const uint16_t* SK_RESTRICT table = s.fBitmap->getColorTable()->lock16BitCache(); michael@0: const uint8_t* SK_RESTRICT srcAddr = (const uint8_t*)s.fBitmap->getPixels(); michael@0: michael@0: // buffer is y32, x16, x16, x16, x16, x16 michael@0: // bump srcAddr to the proper row, since we're told Y never changes michael@0: SkASSERT((unsigned)xy[0] < (unsigned)s.fBitmap->height()); michael@0: srcAddr = (const uint8_t*)((const char*)srcAddr + michael@0: xy[0] * s.fBitmap->rowBytes()); michael@0: michael@0: uint8_t src; michael@0: michael@0: if (1 == s.fBitmap->width()) { michael@0: src = srcAddr[0]; michael@0: uint16_t dstValue = table[src]; michael@0: sk_memset16(colors, dstValue, count); michael@0: } else { michael@0: int i; michael@0: int count8 = count >> 3; michael@0: const uint16_t* SK_RESTRICT xx = (const uint16_t*)(xy + 1); michael@0: michael@0: asm volatile ( michael@0: "cmp %[count8], #0 \n\t" // compare loop counter with 0 michael@0: "beq 2f \n\t" // if loop counter == 0, exit michael@0: "1: \n\t" michael@0: "ldmia %[xx]!, {r5, r7, r9, r11} \n\t" // load ptrs to pixels 0-7 michael@0: "subs %[count8], %[count8], #1 \n\t" // decrement loop counter michael@0: "uxth r4, r5 \n\t" // extract ptr 0 michael@0: "mov r5, r5, lsr #16 \n\t" // extract ptr 1 michael@0: "uxth r6, r7 \n\t" // extract ptr 2 michael@0: "mov r7, r7, lsr #16 \n\t" // extract ptr 3 michael@0: "ldrb r4, [%[srcAddr], r4] \n\t" // load pixel 0 from image michael@0: "uxth r8, r9 \n\t" // extract ptr 4 michael@0: "ldrb r5, [%[srcAddr], r5] \n\t" // load pixel 1 from image michael@0: "mov r9, r9, lsr #16 \n\t" // extract ptr 5 michael@0: "ldrb r6, [%[srcAddr], r6] \n\t" // load pixel 2 from image michael@0: "uxth r10, r11 \n\t" // extract ptr 6 michael@0: "ldrb r7, [%[srcAddr], r7] \n\t" // load pixel 3 from image michael@0: "mov r11, r11, lsr #16 \n\t" // extract ptr 7 michael@0: "ldrb r8, [%[srcAddr], r8] \n\t" // load pixel 4 from image michael@0: "add r4, r4, r4 \n\t" // double pixel 0 for RGB565 lookup michael@0: "ldrb r9, [%[srcAddr], r9] \n\t" // load pixel 5 from image michael@0: "add r5, r5, r5 \n\t" // double pixel 1 for RGB565 lookup michael@0: "ldrb r10, [%[srcAddr], r10] \n\t" // load pixel 6 from image michael@0: "add r6, r6, r6 \n\t" // double pixel 2 for RGB565 lookup michael@0: "ldrb r11, [%[srcAddr], r11] \n\t" // load pixel 7 from image michael@0: "add r7, r7, r7 \n\t" // double pixel 3 for RGB565 lookup michael@0: "ldrh r4, [%[table], r4] \n\t" // load pixel 0 RGB565 from colmap michael@0: "add r8, r8, r8 \n\t" // double pixel 4 for RGB565 lookup michael@0: "ldrh r5, [%[table], r5] \n\t" // load pixel 1 RGB565 from colmap michael@0: "add r9, r9, r9 \n\t" // double pixel 5 for RGB565 lookup michael@0: "ldrh r6, [%[table], r6] \n\t" // load pixel 2 RGB565 from colmap michael@0: "add r10, r10, r10 \n\t" // double pixel 6 for RGB565 lookup michael@0: "ldrh r7, [%[table], r7] \n\t" // load pixel 3 RGB565 from colmap michael@0: "add r11, r11, r11 \n\t" // double pixel 7 for RGB565 lookup michael@0: "ldrh r8, [%[table], r8] \n\t" // load pixel 4 RGB565 from colmap michael@0: "ldrh r9, [%[table], r9] \n\t" // load pixel 5 RGB565 from colmap michael@0: "ldrh r10, [%[table], r10] \n\t" // load pixel 6 RGB565 from colmap michael@0: "ldrh r11, [%[table], r11] \n\t" // load pixel 7 RGB565 from colmap michael@0: "pkhbt r5, r4, r5, lsl #16 \n\t" // pack pixels 0 and 1 michael@0: "pkhbt r6, r6, r7, lsl #16 \n\t" // pack pixels 2 and 3 michael@0: "pkhbt r8, r8, r9, lsl #16 \n\t" // pack pixels 4 and 5 michael@0: "pkhbt r10, r10, r11, lsl #16 \n\t" // pack pixels 6 and 7 michael@0: "stmia %[colors]!, {r5, r6, r8, r10} \n\t" // store last 8 pixels michael@0: "bgt 1b \n\t" // loop if counter > 0 michael@0: "2: \n\t" michael@0: : [xx] "+r" (xx), [count8] "+r" (count8), [colors] "+r" (colors) michael@0: : [table] "r" (table), [srcAddr] "r" (srcAddr) michael@0: : "memory", "cc", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11" michael@0: ); michael@0: michael@0: for (i = (count & 7); i > 0; --i) { michael@0: src = srcAddr[*xx++]; *colors++ = table[src]; michael@0: } michael@0: } michael@0: michael@0: s.fBitmap->getColorTable()->unlock16BitCache(); michael@0: } michael@0: michael@0: void SI8_opaque_D32_nofilter_DX_arm( michael@0: const SkBitmapProcState& s, michael@0: const uint32_t* SK_RESTRICT xy, michael@0: int count, michael@0: SkPMColor* SK_RESTRICT colors) SK_ATTRIBUTE_OPTIMIZE_O1; michael@0: michael@0: void SI8_opaque_D32_nofilter_DX_arm(const SkBitmapProcState& s, michael@0: const uint32_t* SK_RESTRICT xy, michael@0: int count, SkPMColor* SK_RESTRICT colors) { michael@0: SkASSERT(count > 0 && colors != NULL); michael@0: SkASSERT(s.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)); michael@0: SkASSERT(SkPaint::kNone_FilterLevel == s.fFilterLevel); michael@0: michael@0: const SkPMColor* SK_RESTRICT table = s.fBitmap->getColorTable()->lockColors(); michael@0: const uint8_t* SK_RESTRICT srcAddr = (const uint8_t*)s.fBitmap->getPixels(); michael@0: michael@0: // buffer is y32, x16, x16, x16, x16, x16 michael@0: // bump srcAddr to the proper row, since we're told Y never changes michael@0: SkASSERT((unsigned)xy[0] < (unsigned)s.fBitmap->height()); michael@0: srcAddr = (const uint8_t*)((const char*)srcAddr + xy[0] * s.fBitmap->rowBytes()); michael@0: michael@0: if (1 == s.fBitmap->width()) { michael@0: uint8_t src = srcAddr[0]; michael@0: SkPMColor dstValue = table[src]; michael@0: sk_memset32(colors, dstValue, count); michael@0: } else { michael@0: const uint16_t* xx = (const uint16_t*)(xy + 1); michael@0: michael@0: asm volatile ( michael@0: "subs %[count], %[count], #8 \n\t" // decrement count by 8, set flags michael@0: "blt 2f \n\t" // if count < 0, branch to singles michael@0: "1: \n\t" // eights loop michael@0: "ldmia %[xx]!, {r5, r7, r9, r11} \n\t" // load ptrs to pixels 0-7 michael@0: "uxth r4, r5 \n\t" // extract ptr 0 michael@0: "mov r5, r5, lsr #16 \n\t" // extract ptr 1 michael@0: "uxth r6, r7 \n\t" // extract ptr 2 michael@0: "mov r7, r7, lsr #16 \n\t" // extract ptr 3 michael@0: "ldrb r4, [%[srcAddr], r4] \n\t" // load pixel 0 from image michael@0: "uxth r8, r9 \n\t" // extract ptr 4 michael@0: "ldrb r5, [%[srcAddr], r5] \n\t" // load pixel 1 from image michael@0: "mov r9, r9, lsr #16 \n\t" // extract ptr 5 michael@0: "ldrb r6, [%[srcAddr], r6] \n\t" // load pixel 2 from image michael@0: "uxth r10, r11 \n\t" // extract ptr 6 michael@0: "ldrb r7, [%[srcAddr], r7] \n\t" // load pixel 3 from image michael@0: "mov r11, r11, lsr #16 \n\t" // extract ptr 7 michael@0: "ldrb r8, [%[srcAddr], r8] \n\t" // load pixel 4 from image michael@0: "ldrb r9, [%[srcAddr], r9] \n\t" // load pixel 5 from image michael@0: "ldrb r10, [%[srcAddr], r10] \n\t" // load pixel 6 from image michael@0: "ldrb r11, [%[srcAddr], r11] \n\t" // load pixel 7 from image michael@0: "ldr r4, [%[table], r4, lsl #2] \n\t" // load pixel 0 SkPMColor from colmap michael@0: "ldr r5, [%[table], r5, lsl #2] \n\t" // load pixel 1 SkPMColor from colmap michael@0: "ldr r6, [%[table], r6, lsl #2] \n\t" // load pixel 2 SkPMColor from colmap michael@0: "ldr r7, [%[table], r7, lsl #2] \n\t" // load pixel 3 SkPMColor from colmap michael@0: "ldr r8, [%[table], r8, lsl #2] \n\t" // load pixel 4 SkPMColor from colmap michael@0: "ldr r9, [%[table], r9, lsl #2] \n\t" // load pixel 5 SkPMColor from colmap michael@0: "ldr r10, [%[table], r10, lsl #2] \n\t" // load pixel 6 SkPMColor from colmap michael@0: "ldr r11, [%[table], r11, lsl #2] \n\t" // load pixel 7 SkPMColor from colmap michael@0: "subs %[count], %[count], #8 \n\t" // decrement loop counter michael@0: "stmia %[colors]!, {r4-r11} \n\t" // store 8 pixels michael@0: "bge 1b \n\t" // loop if counter >= 0 michael@0: "2: \n\t" michael@0: "adds %[count], %[count], #8 \n\t" // fix up counter, set flags michael@0: "beq 4f \n\t" // if count == 0, branch to exit michael@0: "3: \n\t" // singles loop michael@0: "ldrh r4, [%[xx]], #2 \n\t" // load pixel ptr michael@0: "subs %[count], %[count], #1 \n\t" // decrement loop counter michael@0: "ldrb r5, [%[srcAddr], r4] \n\t" // load pixel from image michael@0: "ldr r6, [%[table], r5, lsl #2] \n\t" // load SkPMColor from colmap michael@0: "str r6, [%[colors]], #4 \n\t" // store pixel, update ptr michael@0: "bne 3b \n\t" // loop if counter != 0 michael@0: "4: \n\t" // exit michael@0: : [xx] "+r" (xx), [count] "+r" (count), [colors] "+r" (colors) michael@0: : [table] "r" (table), [srcAddr] "r" (srcAddr) michael@0: : "memory", "cc", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11" michael@0: ); michael@0: } michael@0: michael@0: s.fBitmap->getColorTable()->unlockColors(); michael@0: } michael@0: #endif // SK_ARM_ARCH >= 6 && !defined(SK_CPU_BENDIAN) michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: /* If we replace a sampleproc, then we null-out the associated shaderproc, michael@0: otherwise the shader won't even look at the matrix/sampler michael@0: */ michael@0: void SkBitmapProcState::platformProcs() { michael@0: bool isOpaque = 256 == fAlphaScale; michael@0: bool justDx = false; michael@0: michael@0: if (fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) { michael@0: justDx = true; michael@0: } michael@0: michael@0: switch (fBitmap->config()) { michael@0: case SkBitmap::kIndex8_Config: michael@0: #if SK_ARM_ARCH >= 6 && !defined(SK_CPU_BENDIAN) michael@0: if (justDx && SkPaint::kNone_FilterLevel == fFilterLevel) { michael@0: #if 0 /* crashing on android device */ michael@0: fSampleProc16 = SI8_D16_nofilter_DX_arm; michael@0: fShaderProc16 = NULL; michael@0: #endif michael@0: if (isOpaque) { michael@0: // this one is only very slighty faster than the C version michael@0: fSampleProc32 = SI8_opaque_D32_nofilter_DX_arm; michael@0: fShaderProc32 = NULL; michael@0: } michael@0: } michael@0: #endif michael@0: break; michael@0: default: michael@0: break; michael@0: } michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: extern void platformConvolutionProcs_arm_neon(SkConvolutionProcs* procs); michael@0: michael@0: void platformConvolutionProcs_arm(SkConvolutionProcs* procs) { michael@0: } michael@0: michael@0: void SkBitmapProcState::platformConvolutionProcs(SkConvolutionProcs* procs) { michael@0: SK_ARM_NEON_WRAP(platformConvolutionProcs_arm)(procs); michael@0: }