| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "platform/graphics/gpu/WebGLImageConversion.h" | 6 #include "platform/graphics/gpu/WebGLImageConversion.h" |
| 7 | 7 |
| 8 #include "platform/CheckedInt.h" | 8 #include "platform/CheckedInt.h" |
| 9 #include "platform/graphics/ImageObserver.h" | 9 #include "platform/graphics/ImageObserver.h" |
| 10 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" | 10 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 // Some code are merged back from Mozilla code in http://mxr.mozilla.org/mozilla
-central/source/content/canvas/src/WebGLTexelConversions.h | 357 // Some code are merged back from Mozilla code in http://mxr.mozilla.org/mozilla
-central/source/content/canvas/src/WebGLTexelConversions.h |
| 358 | 358 |
| 359 //---------------------------------------------------------------------- | 359 //---------------------------------------------------------------------- |
| 360 // Pixel unpacking routines. | 360 // Pixel unpacking routines. |
| 361 template<int format, typename SourceType, typename DstType> | 361 template<int format, typename SourceType, typename DstType> |
| 362 void unpack(const SourceType*, DstType*, unsigned) | 362 void unpack(const SourceType*, DstType*, unsigned) |
| 363 { | 363 { |
| 364 ASSERT_NOT_REACHED(); | 364 ASSERT_NOT_REACHED(); |
| 365 } | 365 } |
| 366 | 366 |
| 367 template<> void unpack<WebGLImageConversion::DataFormatRGB8, uint8_t, uint8_t>(c
onst uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) | |
| 368 { | |
| 369 for (unsigned i = 0; i < pixelsPerRow; ++i) { | |
| 370 destination[0] = source[0]; | |
| 371 destination[1] = source[1]; | |
| 372 destination[2] = source[2]; | |
| 373 destination[3] = 0xFF; | |
| 374 source += 3; | |
| 375 destination += 4; | |
| 376 } | |
| 377 } | |
| 378 | |
| 379 template<> void unpack<WebGLImageConversion::DataFormatBGR8, uint8_t, uint8_t>(c
onst uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) | |
| 380 { | |
| 381 for (unsigned i = 0; i < pixelsPerRow; ++i) { | |
| 382 destination[0] = source[2]; | |
| 383 destination[1] = source[1]; | |
| 384 destination[2] = source[0]; | |
| 385 destination[3] = 0xFF; | |
| 386 source += 3; | |
| 387 destination += 4; | |
| 388 } | |
| 389 } | |
| 390 | |
| 391 template<> void unpack<WebGLImageConversion::DataFormatARGB8, uint8_t, uint8_t>(
const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) | 367 template<> void unpack<WebGLImageConversion::DataFormatARGB8, uint8_t, uint8_t>(
const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) |
| 392 { | 368 { |
| 393 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 369 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 394 destination[0] = source[1]; | 370 destination[0] = source[1]; |
| 395 destination[1] = source[2]; | 371 destination[1] = source[2]; |
| 396 destination[2] = source[3]; | 372 destination[2] = source[3]; |
| 397 destination[3] = source[0]; | 373 destination[3] = source[0]; |
| 398 source += 4; | 374 source += 4; |
| 399 destination += 4; | 375 destination += 4; |
| 400 } | 376 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 uint8_t a = packedValue & 0x0F; | 438 uint8_t a = packedValue & 0x0F; |
| 463 destination[0] = r << 4 | r; | 439 destination[0] = r << 4 | r; |
| 464 destination[1] = g << 4 | g; | 440 destination[1] = g << 4 | g; |
| 465 destination[2] = b << 4 | b; | 441 destination[2] = b << 4 | b; |
| 466 destination[3] = a << 4 | a; | 442 destination[3] = a << 4 | a; |
| 467 source += 1; | 443 source += 1; |
| 468 destination += 4; | 444 destination += 4; |
| 469 } | 445 } |
| 470 } | 446 } |
| 471 | 447 |
| 472 template<> void unpack<WebGLImageConversion::DataFormatRGB565, uint16_t, uint8_t
>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow) | |
| 473 { | |
| 474 #if HAVE(ARM_NEON_INTRINSICS) | |
| 475 SIMD::unpackOneRowOfRGB565ToRGBA8(source, destination, pixelsPerRow); | |
| 476 #endif | |
| 477 for (unsigned i = 0; i < pixelsPerRow; ++i) { | |
| 478 uint16_t packedValue = source[0]; | |
| 479 uint8_t r = packedValue >> 11; | |
| 480 uint8_t g = (packedValue >> 5) & 0x3F; | |
| 481 uint8_t b = packedValue & 0x1F; | |
| 482 destination[0] = (r << 3) | (r & 0x7); | |
| 483 destination[1] = (g << 2) | (g & 0x3); | |
| 484 destination[2] = (b << 3) | (b & 0x7); | |
| 485 destination[3] = 0xFF; | |
| 486 source += 1; | |
| 487 destination += 4; | |
| 488 } | |
| 489 } | |
| 490 | |
| 491 template<> void unpack<WebGLImageConversion::DataFormatR8, uint8_t, uint8_t>(con
st uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) | |
| 492 { | |
| 493 for (unsigned i = 0; i < pixelsPerRow; ++i) { | |
| 494 destination[0] = source[0]; | |
| 495 destination[1] = source[0]; | |
| 496 destination[2] = source[0]; | |
| 497 destination[3] = 0xFF; | |
| 498 source += 1; | |
| 499 destination += 4; | |
| 500 } | |
| 501 } | |
| 502 | |
| 503 template<> void unpack<WebGLImageConversion::DataFormatRA8, uint8_t, uint8_t>(co
nst uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) | 448 template<> void unpack<WebGLImageConversion::DataFormatRA8, uint8_t, uint8_t>(co
nst uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) |
| 504 { | 449 { |
| 505 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 450 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 506 destination[0] = source[0]; | 451 destination[0] = source[0]; |
| 507 destination[1] = source[0]; | 452 destination[1] = source[0]; |
| 508 destination[2] = source[0]; | 453 destination[2] = source[0]; |
| 509 destination[3] = source[1]; | 454 destination[3] = source[1]; |
| 510 source += 2; | 455 source += 2; |
| 511 destination += 4; | 456 destination += 4; |
| 512 } | 457 } |
| 513 } | 458 } |
| 514 | 459 |
| 515 template<> void unpack<WebGLImageConversion::DataFormatAR8, uint8_t, uint8_t>(co
nst uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) | 460 template<> void unpack<WebGLImageConversion::DataFormatAR8, uint8_t, uint8_t>(co
nst uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) |
| 516 { | 461 { |
| 517 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 462 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 518 destination[0] = source[1]; | 463 destination[0] = source[1]; |
| 519 destination[1] = source[1]; | 464 destination[1] = source[1]; |
| 520 destination[2] = source[1]; | 465 destination[2] = source[1]; |
| 521 destination[3] = source[0]; | 466 destination[3] = source[0]; |
| 522 source += 2; | 467 source += 2; |
| 523 destination += 4; | 468 destination += 4; |
| 524 } | 469 } |
| 525 } | 470 } |
| 526 | 471 |
| 527 template<> void unpack<WebGLImageConversion::DataFormatA8, uint8_t, uint8_t>(con
st uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) | |
| 528 { | |
| 529 for (unsigned i = 0; i < pixelsPerRow; ++i) { | |
| 530 destination[0] = 0x0; | |
| 531 destination[1] = 0x0; | |
| 532 destination[2] = 0x0; | |
| 533 destination[3] = source[0]; | |
| 534 source += 1; | |
| 535 destination += 4; | |
| 536 } | |
| 537 } | |
| 538 | |
| 539 template<> void unpack<WebGLImageConversion::DataFormatRGBA8, uint8_t, float>(co
nst uint8_t* source, float* destination, unsigned pixelsPerRow) | 472 template<> void unpack<WebGLImageConversion::DataFormatRGBA8, uint8_t, float>(co
nst uint8_t* source, float* destination, unsigned pixelsPerRow) |
| 540 { | 473 { |
| 541 const float scaleFactor = 1.0f / 255.0f; | 474 const float scaleFactor = 1.0f / 255.0f; |
| 542 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 475 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 543 destination[0] = source[0] * scaleFactor; | 476 destination[0] = source[0] * scaleFactor; |
| 544 destination[1] = source[1] * scaleFactor; | 477 destination[1] = source[1] * scaleFactor; |
| 545 destination[2] = source[2] * scaleFactor; | 478 destination[2] = source[2] * scaleFactor; |
| 546 destination[3] = source[3] * scaleFactor; | 479 destination[3] = source[3] * scaleFactor; |
| 547 source += 4; | 480 source += 4; |
| 548 destination += 4; | 481 destination += 4; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 514 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 582 destination[0] = source[1] * scaleFactor; | 515 destination[0] = source[1] * scaleFactor; |
| 583 destination[1] = source[2] * scaleFactor; | 516 destination[1] = source[2] * scaleFactor; |
| 584 destination[2] = source[3] * scaleFactor; | 517 destination[2] = source[3] * scaleFactor; |
| 585 destination[3] = source[0] * scaleFactor; | 518 destination[3] = source[0] * scaleFactor; |
| 586 source += 4; | 519 source += 4; |
| 587 destination += 4; | 520 destination += 4; |
| 588 } | 521 } |
| 589 } | 522 } |
| 590 | 523 |
| 591 template<> void unpack<WebGLImageConversion::DataFormatRGB8, uint8_t, float>(con
st uint8_t* source, float* destination, unsigned pixelsPerRow) | |
| 592 { | |
| 593 const float scaleFactor = 1.0f / 255.0f; | |
| 594 for (unsigned i = 0; i < pixelsPerRow; ++i) { | |
| 595 destination[0] = source[0] * scaleFactor; | |
| 596 destination[1] = source[1] * scaleFactor; | |
| 597 destination[2] = source[2] * scaleFactor; | |
| 598 destination[3] = 1; | |
| 599 source += 3; | |
| 600 destination += 4; | |
| 601 } | |
| 602 } | |
| 603 | |
| 604 template<> void unpack<WebGLImageConversion::DataFormatBGR8, uint8_t, float>(con
st uint8_t* source, float* destination, unsigned pixelsPerRow) | |
| 605 { | |
| 606 const float scaleFactor = 1.0f / 255.0f; | |
| 607 for (unsigned i = 0; i < pixelsPerRow; ++i) { | |
| 608 destination[0] = source[2] * scaleFactor; | |
| 609 destination[1] = source[1] * scaleFactor; | |
| 610 destination[2] = source[0] * scaleFactor; | |
| 611 destination[3] = 1; | |
| 612 source += 3; | |
| 613 destination += 4; | |
| 614 } | |
| 615 } | |
| 616 | |
| 617 template<> void unpack<WebGLImageConversion::DataFormatRGB32F, float, float>(con
st float* source, float* destination, unsigned pixelsPerRow) | |
| 618 { | |
| 619 for (unsigned i = 0; i < pixelsPerRow; ++i) { | |
| 620 destination[0] = source[0]; | |
| 621 destination[1] = source[1]; | |
| 622 destination[2] = source[2]; | |
| 623 destination[3] = 1; | |
| 624 source += 3; | |
| 625 destination += 4; | |
| 626 } | |
| 627 } | |
| 628 | |
| 629 template<> void unpack<WebGLImageConversion::DataFormatR32F, float, float>(const
float* source, float* destination, unsigned pixelsPerRow) | |
| 630 { | |
| 631 for (unsigned i = 0; i < pixelsPerRow; ++i) { | |
| 632 destination[0] = source[0]; | |
| 633 destination[1] = source[0]; | |
| 634 destination[2] = source[0]; | |
| 635 destination[3] = 1; | |
| 636 source += 1; | |
| 637 destination += 4; | |
| 638 } | |
| 639 } | |
| 640 | |
| 641 template<> void unpack<WebGLImageConversion::DataFormatRA32F, float, float>(cons
t float* source, float* destination, unsigned pixelsPerRow) | 524 template<> void unpack<WebGLImageConversion::DataFormatRA32F, float, float>(cons
t float* source, float* destination, unsigned pixelsPerRow) |
| 642 { | 525 { |
| 643 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 526 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 644 destination[0] = source[0]; | 527 destination[0] = source[0]; |
| 645 destination[1] = source[0]; | 528 destination[1] = source[0]; |
| 646 destination[2] = source[0]; | 529 destination[2] = source[0]; |
| 647 destination[3] = source[1]; | 530 destination[3] = source[1]; |
| 648 source += 2; | 531 source += 2; |
| 649 destination += 4; | 532 destination += 4; |
| 650 } | 533 } |
| 651 } | 534 } |
| 652 | 535 |
| 653 template<> void unpack<WebGLImageConversion::DataFormatA32F, float, float>(const
float* source, float* destination, unsigned pixelsPerRow) | |
| 654 { | |
| 655 for (unsigned i = 0; i < pixelsPerRow; ++i) { | |
| 656 destination[0] = 0; | |
| 657 destination[1] = 0; | |
| 658 destination[2] = 0; | |
| 659 destination[3] = source[0]; | |
| 660 source += 1; | |
| 661 destination += 4; | |
| 662 } | |
| 663 } | |
| 664 | |
| 665 //---------------------------------------------------------------------- | 536 //---------------------------------------------------------------------- |
| 666 // Pixel packing routines. | 537 // Pixel packing routines. |
| 667 // | 538 // |
| 668 | 539 |
| 669 template<int format, int alphaOp, typename SourceType, typename DstType> | 540 template<int format, int alphaOp, typename SourceType, typename DstType> |
| 670 void pack(const SourceType*, DstType*, unsigned) | 541 void pack(const SourceType*, DstType*, unsigned) |
| 671 { | 542 { |
| 672 ASSERT_NOT_REACHED(); | 543 ASSERT_NOT_REACHED(); |
| 673 } | 544 } |
| 674 | 545 |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1449 OwnPtr<uint8_t[]> m_unpackedIntermediateSrcData; | 1320 OwnPtr<uint8_t[]> m_unpackedIntermediateSrcData; |
| 1450 }; | 1321 }; |
| 1451 | 1322 |
| 1452 void FormatConverter::convert(WebGLImageConversion::DataFormat srcFormat, WebGLI
mageConversion::DataFormat dstFormat, WebGLImageConversion::AlphaOp alphaOp) | 1323 void FormatConverter::convert(WebGLImageConversion::DataFormat srcFormat, WebGLI
mageConversion::DataFormat dstFormat, WebGLImageConversion::AlphaOp alphaOp) |
| 1453 { | 1324 { |
| 1454 #define FORMATCONVERTER_CASE_SRCFORMAT(SrcFormat) \ | 1325 #define FORMATCONVERTER_CASE_SRCFORMAT(SrcFormat) \ |
| 1455 case SrcFormat: \ | 1326 case SrcFormat: \ |
| 1456 return convert<SrcFormat>(dstFormat, alphaOp); | 1327 return convert<SrcFormat>(dstFormat, alphaOp); |
| 1457 | 1328 |
| 1458 switch (srcFormat) { | 1329 switch (srcFormat) { |
| 1459 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatR8) | |
| 1460 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatA8) | |
| 1461 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatR32F) | |
| 1462 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatA32F) | |
| 1463 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRA8) | 1330 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRA8) |
| 1464 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRA32F
) | 1331 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRA32F
) |
| 1465 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGB8) | |
| 1466 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatBGR8) | |
| 1467 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGB56
5) | |
| 1468 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGB32
F) | |
| 1469 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA8
) | 1332 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA8
) |
| 1470 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatARGB8
) | 1333 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatARGB8
) |
| 1471 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatABGR8
) | 1334 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatABGR8
) |
| 1472 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatAR8) | 1335 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatAR8) |
| 1473 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatBGRA8
) | 1336 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatBGRA8
) |
| 1474 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA5
551) | 1337 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA5
551) |
| 1475 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA4
444) | 1338 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA4
444) |
| 1476 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA3
2F) | 1339 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRGBA3
2F) |
| 1477 default: | 1340 default: |
| 1478 ASSERT_NOT_REACHED(); | 1341 ASSERT_NOT_REACHED(); |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1989 } | 1852 } |
| 1990 | 1853 |
| 1991 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); | 1854 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); |
| 1992 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); | 1855 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); |
| 1993 if (!converter.Success()) | 1856 if (!converter.Success()) |
| 1994 return false; | 1857 return false; |
| 1995 return true; | 1858 return true; |
| 1996 } | 1859 } |
| 1997 | 1860 |
| 1998 } // namespace blink | 1861 } // namespace blink |
| OLD | NEW |