Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: src/codec/SkSwizzler.cpp

Issue 1581933006: Add NEON swap opts and use opts in SkSwizzler (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/opts/SkSwizzler_opts.h » ('j') | src/opts/SkSwizzler_opts.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkOpts.h" 10 #include "SkOpts.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { 296 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
297 297
298 src += offset; 298 src += offset;
299 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 299 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
300 for (int x = 0; x < dstWidth; x++) { 300 for (int x = 0; x < dstWidth; x++) {
301 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); 301 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]);
302 src += deltaSrc; 302 src += deltaSrc;
303 } 303 }
304 } 304 }
305 305
306 static void fast_swizzle_bgrx_to_n32(
307 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set,
308 const SkPMColor ctable[]) {
309
310 // This function must not be called if we are sampling. If we are not
311 // sampling, deltaSrc should equal bpp.
312 SkASSERT(deltaSrc == bpp);
313
314 // The default swizzle supports BGR->N32 and BGRX->N32. This only
315 // supports BGRX->N32.
316 SkASSERT(4 == bpp);
317
318 // These swizzles trust that the alpha value is already 0xFF.
319 #ifdef SK_PMCOLOR_IS_RGBA
320 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width );
321 #else
322 memcpy(dst, src + offset, width * bpp);
msarett 2016/01/14 17:08:25 This could be a no-op if we decoded directly into
scroggo 2016/01/14 17:55:06 +1
323 #endif
324 }
325
306 static void swizzle_bgrx_to_565( 326 static void swizzle_bgrx_to_565(
307 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 327 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
308 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { 328 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
309 329
310 src += offset; 330 src += offset;
311 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 331 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
312 for (int x = 0; x < dstWidth; x++) { 332 for (int x = 0; x < dstWidth; x++) {
313 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); 333 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]);
314 src += deltaSrc; 334 src += deltaSrc;
315 } 335 }
(...skipping 20 matching lines...) Expand all
336 356
337 src += offset; 357 src += offset;
338 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 358 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
339 for (int x = 0; x < dstWidth; x++) { 359 for (int x = 0; x < dstWidth; x++) {
340 uint8_t alpha = src[3]; 360 uint8_t alpha = src[3];
341 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); 361 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]);
342 src += deltaSrc; 362 src += deltaSrc;
343 } 363 }
344 } 364 }
345 365
366 static void fast_swizzle_bgra_to_n32_premul(
scroggo 2016/01/14 17:55:06 Should we have a fast_swizzle to unpremul, as well
msarett 2016/01/14 18:23:19 Sorry I missed this. This is implemented in this
scroggo 2016/01/14 19:08:06 Ah, then should these functions be named something
msarett 2016/01/14 19:45:55 Changed to _to_32.
367 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set,
368 const SkPMColor ctable[]) {
369
370 // This function must not be called if we are sampling. If we are not
371 // sampling, deltaSrc should equal bpp.
372 SkASSERT(deltaSrc == bpp);
373
374 #ifdef SK_PMCOLOR_IS_RGBA
375 SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset) , width);
376 #else
377 SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width );
378 #endif
379 }
380
346 // kRGBX 381 // kRGBX
382
347 static void swizzle_rgbx_to_n32( 383 static void swizzle_rgbx_to_n32(
348 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 384 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
349 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { 385 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
350 386
351 src += offset; 387 src += offset;
352 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 388 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
353 for (int x = 0; x < dstWidth; x++) { 389 for (int x = 0; x < dstWidth; x++) {
354 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); 390 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]);
355 src += deltaSrc; 391 src += deltaSrc;
356 } 392 }
357 } 393 }
358 394
395 static void fast_swizzle_rgbx_to_n32(
396 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set,
397 const SkPMColor ctable[]) {
398
399 // This function must not be called if we are sampling. If we are not
400 // sampling, deltaSrc should equal bpp.
401 SkASSERT(deltaSrc == bpp);
402
403 // The default swizzle supports RGB->N32 and RGBX->N32. This only
404 // supports RGBX->N32.
405 SkASSERT(4 == bpp);
406
407 // These swizzles trust that the alpha value is already 0xFF.
408 #ifdef SK_PMCOLOR_IS_RGBA
409 memcpy(dst, src + offset, width * bpp);
410 #else
411 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width );
412 #endif
413 }
414
359 static void swizzle_rgbx_to_565( 415 static void swizzle_rgbx_to_565(
360 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 416 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
361 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { 417 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) {
362 418
363 src += offset; 419 src += offset;
364 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 420 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
365 for (int x = 0; x < dstWidth; x++) { 421 for (int x = 0; x < dstWidth; x++) {
366 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); 422 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]);
367 src += deltaSrc; 423 src += deltaSrc;
368 } 424 }
369 } 425 }
370 426
371 // kRGBA 427 // kRGBA
428
372 static void swizzle_rgba_to_n32_premul( 429 static void swizzle_rgba_to_n32_premul(
373 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 430 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
374 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { 431 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
375 432
376 src += offset; 433 src += offset;
377 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 434 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
378 for (int x = 0; x < dstWidth; x++) { 435 for (int x = 0; x < dstWidth; x++) {
379 unsigned alpha = src[3]; 436 unsigned alpha = src[3];
380 dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]); 437 dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]);
381 src += deltaSrc; 438 src += deltaSrc;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 case kGray_8_SkColorType: 644 case kGray_8_SkColorType:
588 proc = &swizzle_gray_to_gray; 645 proc = &swizzle_gray_to_gray;
589 break; 646 break;
590 case kRGB_565_SkColorType: 647 case kRGB_565_SkColorType:
591 proc = &swizzle_gray_to_565; 648 proc = &swizzle_gray_to_565;
592 break; 649 break;
593 default: 650 default:
594 break; 651 break;
595 } 652 }
596 break; 653 break;
597 case kBGR:
598 case kBGRX: 654 case kBGRX:
599 switch (dstInfo.colorType()) { 655 switch (dstInfo.colorType()) {
600 case kN32_SkColorType: 656 case kN32_SkColorType:
601 proc = &swizzle_bgrx_to_n32; 657 proc = &swizzle_bgrx_to_n32;
658 fastProc = &fast_swizzle_bgrx_to_n32;
602 break; 659 break;
603 case kRGB_565_SkColorType: 660 case kRGB_565_SkColorType:
604 proc = &swizzle_bgrx_to_565; 661 proc = &swizzle_bgrx_to_565;
605 break; 662 break;
606 default: 663 default:
607 break; 664 break;
608 } 665 }
609 break; 666 break;
610 case kBGRA: 667 case kBGRA:
611 switch (dstInfo.colorType()) { 668 switch (dstInfo.colorType()) {
612 case kN32_SkColorType: 669 case kN32_SkColorType:
613 switch (dstInfo.alphaType()) { 670 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) {
614 case kUnpremul_SkAlphaType: 671 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
672 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _unpremul>;
673 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg rx_to_n32>;
674 } else {
615 proc = &swizzle_bgra_to_n32_unpremul; 675 proc = &swizzle_bgra_to_n32_unpremul;
616 break; 676 fastProc = &fast_swizzle_bgrx_to_n32;
617 case kPremul_SkAlphaType: 677 }
678 } else {
679 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
680 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _premul>;
681 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg ra_to_n32_premul>;
682 } else {
618 proc = &swizzle_bgra_to_n32_premul; 683 proc = &swizzle_bgra_to_n32_premul;
619 break; 684 fastProc = &fast_swizzle_bgra_to_n32_premul;
620 default: 685 }
621 break;
622 } 686 }
623 break; 687 break;
624 default: 688 default:
625 break; 689 break;
626 } 690 }
627 break; 691 break;
628 case kRGBX: 692 case kRGBX:
629 switch (dstInfo.colorType()) { 693 switch (dstInfo.colorType()) {
630 case kN32_SkColorType: 694 case kN32_SkColorType:
631 proc = &swizzle_rgbx_to_n32; 695 proc = &swizzle_rgbx_to_n32;
696 fastProc = &fast_swizzle_rgbx_to_n32;
632 break; 697 break;
633 case kRGB_565_SkColorType: 698 case kRGB_565_SkColorType:
634 proc = &swizzle_rgbx_to_565; 699 proc = &swizzle_rgbx_to_565;
635 default: 700 default:
636 break; 701 break;
637 } 702 }
638 break; 703 break;
639 case kRGBA: 704 case kRGBA:
640 switch (dstInfo.colorType()) { 705 switch (dstInfo.colorType()) {
641 case kN32_SkColorType: 706 case kN32_SkColorType:
642 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { 707 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) {
643 if (SkCodec::kYes_ZeroInitialized == zeroInit) { 708 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
644 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _unpremul>; 709 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _unpremul>;
710 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg bx_to_n32>;
645 } else { 711 } else {
646 proc = &swizzle_rgba_to_n32_unpremul; 712 proc = &swizzle_rgba_to_n32_unpremul;
713 fastProc = &fast_swizzle_rgbx_to_n32;
647 } 714 }
648 } else { 715 } else {
649 if (SkCodec::kYes_ZeroInitialized == zeroInit) { 716 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
650 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _premul>; 717 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _premul>;
651 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg ba_to_n32_premul>; 718 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg ba_to_n32_premul>;
652 } else { 719 } else {
653 proc = &swizzle_rgba_to_n32_premul; 720 proc = &swizzle_rgba_to_n32_premul;
654 fastProc = &fast_swizzle_rgba_to_n32_premul; 721 fastProc = &fast_swizzle_rgba_to_n32_premul;
655 } 722 }
656 } 723 }
657 break; 724 break;
658 default: 725 default:
659 break; 726 break;
660 } 727 }
661 break; 728 break;
662 case kRGB: 729 case kRGB:
663 switch (dstInfo.colorType()) { 730 switch (dstInfo.colorType()) {
664 case kN32_SkColorType: 731 case kN32_SkColorType:
665 proc = &swizzle_rgbx_to_n32; 732 proc = &swizzle_rgbx_to_n32;
666 break; 733 break;
734 case kRGB_565_SkColorType:
msarett 2016/01/14 17:08:25 We have never needed this because we "fill" RGB PN
scroggo 2016/01/14 17:55:06 Is that a separate (future) CL?
msarett 2016/01/14 18:09:09 Yes. Maybe this doesn't belong in this CL?
scroggo 2016/01/14 18:14:51 If it's only needed once we turn off filling, then
msarett 2016/01/14 18:27:51 Done.
735 proc = &swizzle_rgbx_to_565;
736 break;
667 default: 737 default:
668 break; 738 break;
669 } 739 }
740 break;
741 case kBGR:
msarett 2016/01/14 17:08:25 This will diverge from BGRX because of the opt fun
scroggo 2016/01/14 18:14:51 Will there be opts for BGR? Or is that not conduci
msarett 2016/01/14 18:23:19 Yes, I plan on opts for BGR and RGB (coming soon).
742 switch (dstInfo.colorType()) {
743 case kN32_SkColorType:
744 proc = &swizzle_bgrx_to_n32;
745 break;
746 case kRGB_565_SkColorType:
747 proc = &swizzle_bgrx_to_565;
748 break;
749 default:
750 break;
751 }
670 break; 752 break;
671 case kRGB_565: 753 case kRGB_565:
672 switch (dstInfo.colorType()) { 754 switch (dstInfo.colorType()) {
673 case kRGB_565_SkColorType: 755 case kRGB_565_SkColorType:
674 proc = &sample565; 756 proc = &sample565;
675 break; 757 break;
676 default: 758 default:
677 break; 759 break;
678 } 760 }
679 break; 761 break;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 831
750 return fAllocatedWidth; 832 return fAllocatedWidth;
751 } 833 }
752 834
753 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { 835 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) {
754 SkASSERT(nullptr != dst && nullptr != src); 836 SkASSERT(nullptr != dst && nullptr != src);
755 RowProc proc = fFastProc ? fFastProc : fProc; 837 RowProc proc = fFastProc ? fFastProc : fProc;
756 proc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP, 838 proc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP,
757 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); 839 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable);
758 } 840 }
OLDNEW
« no previous file with comments | « no previous file | src/opts/SkSwizzler_opts.h » ('j') | src/opts/SkSwizzler_opts.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698