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

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

Issue 1618003002: Use NEON optimizations for RGB -> RGB(FF) or BGR(FF) 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
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"
11 #include "SkSwizzler.h" 11 #include "SkSwizzler.h"
12 #include "SkTemplates.h" 12 #include "SkTemplates.h"
13 13
14 static void copy(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc , int offset, 14 static void copy(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc , int offset,
15 const SkPMColor ctable[]) { 15 const SkPMColor ctable[]) {
16 // This function must not be called if we are sampling. If we are not 16
msarett 2016/01/21 22:09:07 I could be convinced to add these comments back in
scroggo 2016/01/21 23:19:39 I see no reason to take them out.
msarett 2016/01/21 23:29:47 Added back in.
17 // sampling, deltaSrc should equal bpp.
18 SkASSERT(deltaSrc == bpp); 17 SkASSERT(deltaSrc == bpp);
19 18
20 memcpy(dst, src + offset, width * bpp); 19 memcpy(dst, src + offset, width * bpp);
21 } 20 }
22 21
23 static void sample1(void* dst, const uint8_t* src, int width, int bpp, int delta Src, int offset, 22 static void sample1(void* dst, const uint8_t* src, int width, int bpp, int delta Src, int offset,
24 const SkPMColor ctable[]) { 23 const SkPMColor ctable[]) {
25 src += offset; 24 src += offset;
26 uint8_t* dst8 = (uint8_t*) dst; 25 uint8_t* dst8 = (uint8_t*) dst;
27 for (int x = 0; x < width; x++) { 26 for (int x = 0; x < width; x++) {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 uint8_t alpha = src[3]; 319 uint8_t alpha = src[3];
321 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); 320 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]);
322 src += deltaSrc; 321 src += deltaSrc;
323 } 322 }
324 } 323 }
325 324
326 static void fast_swizzle_bgra_to_n32_unpremul( 325 static void fast_swizzle_bgra_to_n32_unpremul(
327 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, 326 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set,
328 const SkPMColor ctable[]) { 327 const SkPMColor ctable[]) {
329 328
330 // This function must not be called if we are sampling. If we are not
331 // sampling, deltaSrc should equal bpp.
332 SkASSERT(deltaSrc == bpp); 329 SkASSERT(deltaSrc == bpp);
333 330
334 // These swizzles trust that the alpha value is already 0xFF.
335 #ifdef SK_PMCOLOR_IS_RGBA 331 #ifdef SK_PMCOLOR_IS_RGBA
336 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width ); 332 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width );
337 #else 333 #else
338 memcpy(dst, src + offset, width * bpp); 334 memcpy(dst, src + offset, width * bpp);
339 #endif 335 #endif
340 } 336 }
341 337
342 static void swizzle_bgra_to_n32_premul( 338 static void swizzle_bgra_to_n32_premul(
343 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 339 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
344 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { 340 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
345 341
346 src += offset; 342 src += offset;
347 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 343 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
348 for (int x = 0; x < dstWidth; x++) { 344 for (int x = 0; x < dstWidth; x++) {
349 uint8_t alpha = src[3]; 345 uint8_t alpha = src[3];
350 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); 346 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]);
351 src += deltaSrc; 347 src += deltaSrc;
352 } 348 }
353 } 349 }
354 350
355 static void fast_swizzle_bgra_to_n32_premul( 351 static void fast_swizzle_bgra_to_n32_premul(
356 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, 352 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set,
357 const SkPMColor ctable[]) { 353 const SkPMColor ctable[]) {
358 354
359 // This function must not be called if we are sampling. If we are not
360 // sampling, deltaSrc should equal bpp.
361 SkASSERT(deltaSrc == bpp); 355 SkASSERT(deltaSrc == bpp);
362 356
363 #ifdef SK_PMCOLOR_IS_RGBA 357 #ifdef SK_PMCOLOR_IS_RGBA
364 SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset) , width); 358 SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset) , width);
365 #else 359 #else
366 SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width ); 360 SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width );
367 #endif 361 #endif
368 } 362 }
369 363
370 // kRGB 364 // kRGB
371 365
372 static void swizzle_rgb_to_n32( 366 static void swizzle_rgb_to_n32(
373 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 367 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
374 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { 368 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
375 369
376 src += offset; 370 src += offset;
377 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 371 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
378 for (int x = 0; x < dstWidth; x++) { 372 for (int x = 0; x < dstWidth; x++) {
379 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); 373 dst[x] = SkPackARGB32NoCheck(0xFF, src[0], src[1], src[2]);
380 src += deltaSrc; 374 src += deltaSrc;
381 } 375 }
382 } 376 }
383 377
378 static void fast_swizzle_rgb_to_n32(
379 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc,
380 int offset, const SkPMColor ctable[]) {
384 381
382 SkASSERT(deltaSrc == bpp);
383
384 #ifdef SK_PMCOLOR_IS_RGBA
385 SkOpts::xxx_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width);
386 #else
387 SkOpts::xxx_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), w idth);
388 #endif
389 }
385 390
386 static void swizzle_rgb_to_565( 391 static void swizzle_rgb_to_565(
387 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 392 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
388 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { 393 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) {
389 394
390 src += offset; 395 src += offset;
391 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 396 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
392 for (int x = 0; x < dstWidth; x++) { 397 for (int x = 0; x < dstWidth; x++) {
393 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); 398 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]);
394 src += deltaSrc; 399 src += deltaSrc;
(...skipping 12 matching lines...) Expand all
407 unsigned alpha = src[3]; 412 unsigned alpha = src[3];
408 dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]); 413 dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]);
409 src += deltaSrc; 414 src += deltaSrc;
410 } 415 }
411 } 416 }
412 417
413 static void fast_swizzle_rgba_to_n32_premul( 418 static void fast_swizzle_rgba_to_n32_premul(
414 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, 419 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc,
415 int offset, const SkPMColor ctable[]) { 420 int offset, const SkPMColor ctable[]) {
416 421
417 // This function must not be called if we are sampling. If we are not
418 // sampling, deltaSrc should equal bpp.
419 SkASSERT(deltaSrc == bpp); 422 SkASSERT(deltaSrc == bpp);
420 423
421 #ifdef SK_PMCOLOR_IS_RGBA 424 #ifdef SK_PMCOLOR_IS_RGBA
422 SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width ); 425 SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width );
423 #else 426 #else
424 SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset) , width); 427 SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset) , width);
425 #endif 428 #endif
426 } 429 }
427 430
428 static void swizzle_rgba_to_n32_unpremul( 431 static void swizzle_rgba_to_n32_unpremul(
429 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 432 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
430 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { 433 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
431 434
432 src += offset; 435 src += offset;
433 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); 436 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
434 for (int x = 0; x < dstWidth; x++) { 437 for (int x = 0; x < dstWidth; x++) {
435 unsigned alpha = src[3]; 438 unsigned alpha = src[3];
436 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); 439 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]);
437 src += deltaSrc; 440 src += deltaSrc;
438 } 441 }
439 } 442 }
440 443
441 static void fast_swizzle_rgba_to_n32_unpremul( 444 static void fast_swizzle_rgba_to_n32_unpremul(
442 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, 445 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set,
443 const SkPMColor ctable[]) { 446 const SkPMColor ctable[]) {
444 447
445 // This function must not be called if we are sampling. If we are not
446 // sampling, deltaSrc should equal bpp.
447 SkASSERT(deltaSrc == bpp); 448 SkASSERT(deltaSrc == bpp);
448 449
449 // These swizzles trust that the alpha value is already 0xFF.
450 #ifdef SK_PMCOLOR_IS_RGBA 450 #ifdef SK_PMCOLOR_IS_RGBA
451 memcpy(dst, src + offset, width * bpp); 451 memcpy(dst, src + offset, width * bpp);
452 #else 452 #else
453 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width ); 453 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width );
454 #endif 454 #endif
455 } 455 }
456 456
457 // kCMYK 457 // kCMYK
458 // 458 //
459 // CMYK is stored as four bytes per pixel. 459 // CMYK is stored as four bytes per pixel.
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } 675 }
676 break; 676 break;
677 default: 677 default:
678 break; 678 break;
679 } 679 }
680 break; 680 break;
681 case kRGB: 681 case kRGB:
682 switch (dstInfo.colorType()) { 682 switch (dstInfo.colorType()) {
683 case kN32_SkColorType: 683 case kN32_SkColorType:
684 proc = &swizzle_rgb_to_n32; 684 proc = &swizzle_rgb_to_n32;
685 fastProc = &fast_swizzle_rgb_to_n32;
685 break; 686 break;
686 case kRGB_565_SkColorType: 687 case kRGB_565_SkColorType:
687 proc = &swizzle_rgb_to_565; 688 proc = &swizzle_rgb_to_565;
688 default: 689 default:
689 break; 690 break;
690 } 691 }
691 break; 692 break;
692 case kRGBA: 693 case kRGBA:
693 switch (dstInfo.colorType()) { 694 switch (dstInfo.colorType()) {
694 case kN32_SkColorType: 695 case kN32_SkColorType:
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 799
799 return fAllocatedWidth; 800 return fAllocatedWidth;
800 } 801 }
801 802
802 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { 803 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) {
803 SkASSERT(nullptr != dst && nullptr != src); 804 SkASSERT(nullptr != dst && nullptr != src);
804 RowProc proc = fFastProc ? fFastProc : fProc; 805 RowProc proc = fFastProc ? fFastProc : fProc;
805 proc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP, 806 proc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP,
806 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); 807 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable);
807 } 808 }
OLDNEW
« no previous file with comments | « bench/SwizzleBench.cpp ('k') | src/core/SkOpts.h » ('j') | src/opts/SkOpts_ssse3.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698