OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkXfermode.h" | 10 #include "SkXfermode.h" |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 if (0xFF != a) { | 768 if (0xFF != a) { |
769 A = SkAlphaBlend(A, dstA, SkAlpha255To256(a)); | 769 A = SkAlphaBlend(A, dstA, SkAlpha255To256(a)); |
770 } | 770 } |
771 dst[i] = SkToU8(A); | 771 dst[i] = SkToU8(A); |
772 } | 772 } |
773 } | 773 } |
774 } | 774 } |
775 } | 775 } |
776 | 776 |
777 /////////////////////////////////////////////////////////////////////////////// | 777 /////////////////////////////////////////////////////////////////////////////// |
| 778 #ifdef SK_SUPPORT_LEGACY_PROCXFERMODE |
778 | 779 |
779 void SkProcXfermode::xfer32(SkPMColor* SK_RESTRICT dst, | 780 void SkProcXfermode::xfer32(SkPMColor* SK_RESTRICT dst, |
780 const SkPMColor* SK_RESTRICT src, int count, | 781 const SkPMColor* SK_RESTRICT src, int count, |
781 const SkAlpha* SK_RESTRICT aa) const { | 782 const SkAlpha* SK_RESTRICT aa) const { |
782 SkASSERT(dst && src && count >= 0); | 783 SkASSERT(dst && src && count >= 0); |
783 | 784 |
784 SkXfermodeProc proc = fProc; | 785 SkXfermodeProc proc = fProc; |
785 | 786 |
786 if (NULL != proc) { | 787 if (NULL != proc) { |
787 if (NULL == aa) { | 788 if (NULL == aa) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 buffer.writeFunctionPtr((void*)fProc); | 878 buffer.writeFunctionPtr((void*)fProc); |
878 } | 879 } |
879 } | 880 } |
880 | 881 |
881 #ifndef SK_IGNORE_TO_STRING | 882 #ifndef SK_IGNORE_TO_STRING |
882 void SkProcXfermode::toString(SkString* str) const { | 883 void SkProcXfermode::toString(SkString* str) const { |
883 str->appendf("SkProcXfermode: %p", fProc); | 884 str->appendf("SkProcXfermode: %p", fProc); |
884 } | 885 } |
885 #endif | 886 #endif |
886 | 887 |
| 888 #endif |
887 ////////////////////////////////////////////////////////////////////////////// | 889 ////////////////////////////////////////////////////////////////////////////// |
888 | 890 |
889 #if SK_SUPPORT_GPU | 891 #if SK_SUPPORT_GPU |
890 | 892 |
891 #include "GrEffect.h" | 893 #include "GrEffect.h" |
892 #include "GrCoordTransform.h" | 894 #include "GrCoordTransform.h" |
893 #include "GrEffectUnitTest.h" | 895 #include "GrEffectUnitTest.h" |
894 #include "GrTBackendEffectFactory.h" | 896 #include "GrTBackendEffectFactory.h" |
895 #include "gl/GrGLEffect.h" | 897 #include "gl/GrGLEffect.h" |
896 | 898 |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1351 | 1353 |
1352 SkProcCoeffXfermode::SkProcCoeffXfermode(SkReadBuffer& buffer) : INHERITED(buffe
r) { | 1354 SkProcCoeffXfermode::SkProcCoeffXfermode(SkReadBuffer& buffer) : INHERITED(buffe
r) { |
1353 uint32_t mode32 = buffer.read32() % SK_ARRAY_COUNT(gProcCoeffs); | 1355 uint32_t mode32 = buffer.read32() % SK_ARRAY_COUNT(gProcCoeffs); |
1354 if (mode32 >= SK_ARRAY_COUNT(gProcCoeffs)) { | 1356 if (mode32 >= SK_ARRAY_COUNT(gProcCoeffs)) { |
1355 // out of range, just set to something harmless | 1357 // out of range, just set to something harmless |
1356 mode32 = SkXfermode::kSrcOut_Mode; | 1358 mode32 = SkXfermode::kSrcOut_Mode; |
1357 } | 1359 } |
1358 fMode = (SkXfermode::Mode)mode32; | 1360 fMode = (SkXfermode::Mode)mode32; |
1359 | 1361 |
1360 const ProcCoeff& rec = gProcCoeffs[fMode]; | 1362 const ProcCoeff& rec = gProcCoeffs[fMode]; |
| 1363 fProc = rec.fProc; |
1361 // these may be valid, or may be CANNOT_USE_COEFF | 1364 // these may be valid, or may be CANNOT_USE_COEFF |
1362 fSrcCoeff = rec.fSC; | 1365 fSrcCoeff = rec.fSC; |
1363 fDstCoeff = rec.fDC; | 1366 fDstCoeff = rec.fDC; |
1364 // now update our function-ptr in the super class | |
1365 this->INHERITED::setProc(rec.fProc); | |
1366 } | 1367 } |
1367 | 1368 |
1368 bool SkProcCoeffXfermode::asMode(Mode* mode) const { | 1369 bool SkProcCoeffXfermode::asMode(Mode* mode) const { |
1369 if (mode) { | 1370 if (mode) { |
1370 *mode = fMode; | 1371 *mode = fMode; |
1371 } | 1372 } |
1372 return true; | 1373 return true; |
1373 } | 1374 } |
1374 | 1375 |
1375 bool SkProcCoeffXfermode::asCoeff(Coeff* sc, Coeff* dc) const { | 1376 bool SkProcCoeffXfermode::asCoeff(Coeff* sc, Coeff* dc) const { |
1376 if (CANNOT_USE_COEFF == fSrcCoeff) { | 1377 if (CANNOT_USE_COEFF == fSrcCoeff) { |
1377 return false; | 1378 return false; |
1378 } | 1379 } |
1379 | 1380 |
1380 if (sc) { | 1381 if (sc) { |
1381 *sc = fSrcCoeff; | 1382 *sc = fSrcCoeff; |
1382 } | 1383 } |
1383 if (dc) { | 1384 if (dc) { |
1384 *dc = fDstCoeff; | 1385 *dc = fDstCoeff; |
1385 } | 1386 } |
1386 return true; | 1387 return true; |
1387 } | 1388 } |
1388 | 1389 |
| 1390 void SkProcCoeffXfermode::xfer32(SkPMColor* SK_RESTRICT dst, |
| 1391 const SkPMColor* SK_RESTRICT src, int count, |
| 1392 const SkAlpha* SK_RESTRICT aa) const { |
| 1393 SkASSERT(dst && src && count >= 0); |
| 1394 |
| 1395 SkXfermodeProc proc = fProc; |
| 1396 |
| 1397 if (NULL != proc) { |
| 1398 if (NULL == aa) { |
| 1399 for (int i = count - 1; i >= 0; --i) { |
| 1400 dst[i] = proc(src[i], dst[i]); |
| 1401 } |
| 1402 } else { |
| 1403 for (int i = count - 1; i >= 0; --i) { |
| 1404 unsigned a = aa[i]; |
| 1405 if (0 != a) { |
| 1406 SkPMColor dstC = dst[i]; |
| 1407 SkPMColor C = proc(src[i], dstC); |
| 1408 if (a != 0xFF) { |
| 1409 C = SkFourByteInterp(C, dstC, a); |
| 1410 } |
| 1411 dst[i] = C; |
| 1412 } |
| 1413 } |
| 1414 } |
| 1415 } |
| 1416 } |
| 1417 |
| 1418 void SkProcCoeffXfermode::xfer16(uint16_t* SK_RESTRICT dst, |
| 1419 const SkPMColor* SK_RESTRICT src, int count, |
| 1420 const SkAlpha* SK_RESTRICT aa) const { |
| 1421 SkASSERT(dst && src && count >= 0); |
| 1422 |
| 1423 SkXfermodeProc proc = fProc; |
| 1424 |
| 1425 if (NULL != proc) { |
| 1426 if (NULL == aa) { |
| 1427 for (int i = count - 1; i >= 0; --i) { |
| 1428 SkPMColor dstC = SkPixel16ToPixel32(dst[i]); |
| 1429 dst[i] = SkPixel32ToPixel16_ToU16(proc(src[i], dstC)); |
| 1430 } |
| 1431 } else { |
| 1432 for (int i = count - 1; i >= 0; --i) { |
| 1433 unsigned a = aa[i]; |
| 1434 if (0 != a) { |
| 1435 SkPMColor dstC = SkPixel16ToPixel32(dst[i]); |
| 1436 SkPMColor C = proc(src[i], dstC); |
| 1437 if (0xFF != a) { |
| 1438 C = SkFourByteInterp(C, dstC, a); |
| 1439 } |
| 1440 dst[i] = SkPixel32ToPixel16_ToU16(C); |
| 1441 } |
| 1442 } |
| 1443 } |
| 1444 } |
| 1445 } |
| 1446 |
| 1447 void SkProcCoeffXfermode::xferA8(SkAlpha* SK_RESTRICT dst, |
| 1448 const SkPMColor* SK_RESTRICT src, int count, |
| 1449 const SkAlpha* SK_RESTRICT aa) const { |
| 1450 SkASSERT(dst && src && count >= 0); |
| 1451 |
| 1452 SkXfermodeProc proc = fProc; |
| 1453 |
| 1454 if (NULL != proc) { |
| 1455 if (NULL == aa) { |
| 1456 for (int i = count - 1; i >= 0; --i) { |
| 1457 SkPMColor res = proc(src[i], dst[i] << SK_A32_SHIFT); |
| 1458 dst[i] = SkToU8(SkGetPackedA32(res)); |
| 1459 } |
| 1460 } else { |
| 1461 for (int i = count - 1; i >= 0; --i) { |
| 1462 unsigned a = aa[i]; |
| 1463 if (0 != a) { |
| 1464 SkAlpha dstA = dst[i]; |
| 1465 SkPMColor res = proc(src[i], dstA << SK_A32_SHIFT); |
| 1466 unsigned A = SkGetPackedA32(res); |
| 1467 if (0xFF != a) { |
| 1468 A = SkAlphaBlend(A, dstA, SkAlpha255To256(a)); |
| 1469 } |
| 1470 dst[i] = SkToU8(A); |
| 1471 } |
| 1472 } |
| 1473 } |
| 1474 } |
| 1475 } |
| 1476 |
1389 #if SK_SUPPORT_GPU | 1477 #if SK_SUPPORT_GPU |
1390 bool SkProcCoeffXfermode::asNewEffect(GrEffectRef** effect, | 1478 bool SkProcCoeffXfermode::asNewEffect(GrEffectRef** effect, |
1391 GrTexture* background) const { | 1479 GrTexture* background) const { |
1392 if (XferEffect::IsSupportedMode(fMode)) { | 1480 if (XferEffect::IsSupportedMode(fMode)) { |
1393 if (NULL != effect) { | 1481 if (NULL != effect) { |
1394 *effect = XferEffect::Create(fMode, background); | 1482 *effect = XferEffect::Create(fMode, background); |
1395 SkASSERT(NULL != *effect); | 1483 SkASSERT(NULL != *effect); |
1396 } | 1484 } |
1397 return true; | 1485 return true; |
1398 } | 1486 } |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1994 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSrcXfermode) | 2082 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSrcXfermode) |
1995 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstInXfermode) | 2083 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstInXfermode) |
1996 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstOutXfermode) | 2084 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstOutXfermode) |
1997 #if !SK_ARM_NEON_IS_NONE | 2085 #if !SK_ARM_NEON_IS_NONE |
1998 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkNEONProcCoeffXfermode) | 2086 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkNEONProcCoeffXfermode) |
1999 #endif | 2087 #endif |
2000 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS) | 2088 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS) |
2001 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSSE2ProcCoeffXfermode) | 2089 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSSE2ProcCoeffXfermode) |
2002 #endif | 2090 #endif |
2003 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2091 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |