| 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 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui
lder(); | 833 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui
lder(); |
| 834 const char* dstColor; | 834 const char* dstColor; |
| 835 if (backgroundTex) { | 835 if (backgroundTex) { |
| 836 dstColor = "bgColor"; | 836 dstColor = "bgColor"; |
| 837 fsBuilder->codeAppendf("\t\tvec4 %s = ", dstColor); | 837 fsBuilder->codeAppendf("\t\tvec4 %s = ", dstColor); |
| 838 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), c
oords[0].type()); | 838 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), c
oords[0].type()); |
| 839 fsBuilder->codeAppendf(";\n"); | 839 fsBuilder->codeAppendf(";\n"); |
| 840 } else { | 840 } else { |
| 841 dstColor = fsBuilder->dstColor(); | 841 dstColor = fsBuilder->dstColor(); |
| 842 } | 842 } |
| 843 SkASSERT(NULL != dstColor); | 843 SkASSERT(dstColor); |
| 844 | 844 |
| 845 // We don't try to optimize for this case at all | 845 // We don't try to optimize for this case at all |
| 846 if (NULL == inputColor) { | 846 if (NULL == inputColor) { |
| 847 fsBuilder->codeAppendf("\t\tconst vec4 ones = vec4(1);\n"); | 847 fsBuilder->codeAppendf("\t\tconst vec4 ones = vec4(1);\n"); |
| 848 inputColor = "ones"; | 848 inputColor = "ones"; |
| 849 } | 849 } |
| 850 fsBuilder->codeAppendf("\t\t// SkXfermode::Mode: %s\n", SkXfermode::
ModeName(mode)); | 850 fsBuilder->codeAppendf("\t\t// SkXfermode::Mode: %s\n", SkXfermode::
ModeName(mode)); |
| 851 | 851 |
| 852 // These all perform src-over on the alpha channel. | 852 // These all perform src-over on the alpha channel. |
| 853 fsBuilder->codeAppendf("\t\t%s.a = %s.a + (1.0 - %s.a) * %s.a;\n", | 853 fsBuilder->codeAppendf("\t\t%s.a = %s.a + (1.0 - %s.a) * %s.a;\n", |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 return true; | 1291 return true; |
| 1292 } | 1292 } |
| 1293 | 1293 |
| 1294 void SkProcCoeffXfermode::xfer32(SkPMColor* SK_RESTRICT dst, | 1294 void SkProcCoeffXfermode::xfer32(SkPMColor* SK_RESTRICT dst, |
| 1295 const SkPMColor* SK_RESTRICT src, int count, | 1295 const SkPMColor* SK_RESTRICT src, int count, |
| 1296 const SkAlpha* SK_RESTRICT aa) const { | 1296 const SkAlpha* SK_RESTRICT aa) const { |
| 1297 SkASSERT(dst && src && count >= 0); | 1297 SkASSERT(dst && src && count >= 0); |
| 1298 | 1298 |
| 1299 SkXfermodeProc proc = fProc; | 1299 SkXfermodeProc proc = fProc; |
| 1300 | 1300 |
| 1301 if (NULL != proc) { | 1301 if (proc) { |
| 1302 if (NULL == aa) { | 1302 if (NULL == aa) { |
| 1303 for (int i = count - 1; i >= 0; --i) { | 1303 for (int i = count - 1; i >= 0; --i) { |
| 1304 dst[i] = proc(src[i], dst[i]); | 1304 dst[i] = proc(src[i], dst[i]); |
| 1305 } | 1305 } |
| 1306 } else { | 1306 } else { |
| 1307 for (int i = count - 1; i >= 0; --i) { | 1307 for (int i = count - 1; i >= 0; --i) { |
| 1308 unsigned a = aa[i]; | 1308 unsigned a = aa[i]; |
| 1309 if (0 != a) { | 1309 if (0 != a) { |
| 1310 SkPMColor dstC = dst[i]; | 1310 SkPMColor dstC = dst[i]; |
| 1311 SkPMColor C = proc(src[i], dstC); | 1311 SkPMColor C = proc(src[i], dstC); |
| 1312 if (a != 0xFF) { | 1312 if (a != 0xFF) { |
| 1313 C = SkFourByteInterp(C, dstC, a); | 1313 C = SkFourByteInterp(C, dstC, a); |
| 1314 } | 1314 } |
| 1315 dst[i] = C; | 1315 dst[i] = C; |
| 1316 } | 1316 } |
| 1317 } | 1317 } |
| 1318 } | 1318 } |
| 1319 } | 1319 } |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 void SkProcCoeffXfermode::xfer16(uint16_t* SK_RESTRICT dst, | 1322 void SkProcCoeffXfermode::xfer16(uint16_t* SK_RESTRICT dst, |
| 1323 const SkPMColor* SK_RESTRICT src, int count, | 1323 const SkPMColor* SK_RESTRICT src, int count, |
| 1324 const SkAlpha* SK_RESTRICT aa) const { | 1324 const SkAlpha* SK_RESTRICT aa) const { |
| 1325 SkASSERT(dst && src && count >= 0); | 1325 SkASSERT(dst && src && count >= 0); |
| 1326 | 1326 |
| 1327 SkXfermodeProc proc = fProc; | 1327 SkXfermodeProc proc = fProc; |
| 1328 | 1328 |
| 1329 if (NULL != proc) { | 1329 if (proc) { |
| 1330 if (NULL == aa) { | 1330 if (NULL == aa) { |
| 1331 for (int i = count - 1; i >= 0; --i) { | 1331 for (int i = count - 1; i >= 0; --i) { |
| 1332 SkPMColor dstC = SkPixel16ToPixel32(dst[i]); | 1332 SkPMColor dstC = SkPixel16ToPixel32(dst[i]); |
| 1333 dst[i] = SkPixel32ToPixel16_ToU16(proc(src[i], dstC)); | 1333 dst[i] = SkPixel32ToPixel16_ToU16(proc(src[i], dstC)); |
| 1334 } | 1334 } |
| 1335 } else { | 1335 } else { |
| 1336 for (int i = count - 1; i >= 0; --i) { | 1336 for (int i = count - 1; i >= 0; --i) { |
| 1337 unsigned a = aa[i]; | 1337 unsigned a = aa[i]; |
| 1338 if (0 != a) { | 1338 if (0 != a) { |
| 1339 SkPMColor dstC = SkPixel16ToPixel32(dst[i]); | 1339 SkPMColor dstC = SkPixel16ToPixel32(dst[i]); |
| 1340 SkPMColor C = proc(src[i], dstC); | 1340 SkPMColor C = proc(src[i], dstC); |
| 1341 if (0xFF != a) { | 1341 if (0xFF != a) { |
| 1342 C = SkFourByteInterp(C, dstC, a); | 1342 C = SkFourByteInterp(C, dstC, a); |
| 1343 } | 1343 } |
| 1344 dst[i] = SkPixel32ToPixel16_ToU16(C); | 1344 dst[i] = SkPixel32ToPixel16_ToU16(C); |
| 1345 } | 1345 } |
| 1346 } | 1346 } |
| 1347 } | 1347 } |
| 1348 } | 1348 } |
| 1349 } | 1349 } |
| 1350 | 1350 |
| 1351 void SkProcCoeffXfermode::xferA8(SkAlpha* SK_RESTRICT dst, | 1351 void SkProcCoeffXfermode::xferA8(SkAlpha* SK_RESTRICT dst, |
| 1352 const SkPMColor* SK_RESTRICT src, int count, | 1352 const SkPMColor* SK_RESTRICT src, int count, |
| 1353 const SkAlpha* SK_RESTRICT aa) const { | 1353 const SkAlpha* SK_RESTRICT aa) const { |
| 1354 SkASSERT(dst && src && count >= 0); | 1354 SkASSERT(dst && src && count >= 0); |
| 1355 | 1355 |
| 1356 SkXfermodeProc proc = fProc; | 1356 SkXfermodeProc proc = fProc; |
| 1357 | 1357 |
| 1358 if (NULL != proc) { | 1358 if (proc) { |
| 1359 if (NULL == aa) { | 1359 if (NULL == aa) { |
| 1360 for (int i = count - 1; i >= 0; --i) { | 1360 for (int i = count - 1; i >= 0; --i) { |
| 1361 SkPMColor res = proc(src[i], dst[i] << SK_A32_SHIFT); | 1361 SkPMColor res = proc(src[i], dst[i] << SK_A32_SHIFT); |
| 1362 dst[i] = SkToU8(SkGetPackedA32(res)); | 1362 dst[i] = SkToU8(SkGetPackedA32(res)); |
| 1363 } | 1363 } |
| 1364 } else { | 1364 } else { |
| 1365 for (int i = count - 1; i >= 0; --i) { | 1365 for (int i = count - 1; i >= 0; --i) { |
| 1366 unsigned a = aa[i]; | 1366 unsigned a = aa[i]; |
| 1367 if (0 != a) { | 1367 if (0 != a) { |
| 1368 SkAlpha dstA = dst[i]; | 1368 SkAlpha dstA = dst[i]; |
| 1369 SkPMColor res = proc(src[i], dstA << SK_A32_SHIFT); | 1369 SkPMColor res = proc(src[i], dstA << SK_A32_SHIFT); |
| 1370 unsigned A = SkGetPackedA32(res); | 1370 unsigned A = SkGetPackedA32(res); |
| 1371 if (0xFF != a) { | 1371 if (0xFF != a) { |
| 1372 A = SkAlphaBlend(A, dstA, SkAlpha255To256(a)); | 1372 A = SkAlphaBlend(A, dstA, SkAlpha255To256(a)); |
| 1373 } | 1373 } |
| 1374 dst[i] = SkToU8(A); | 1374 dst[i] = SkToU8(A); |
| 1375 } | 1375 } |
| 1376 } | 1376 } |
| 1377 } | 1377 } |
| 1378 } | 1378 } |
| 1379 } | 1379 } |
| 1380 | 1380 |
| 1381 #if SK_SUPPORT_GPU | 1381 #if SK_SUPPORT_GPU |
| 1382 bool SkProcCoeffXfermode::asNewEffect(GrEffect** effect, GrTexture* background)
const { | 1382 bool SkProcCoeffXfermode::asNewEffect(GrEffect** effect, GrTexture* background)
const { |
| 1383 if (XferEffect::IsSupportedMode(fMode)) { | 1383 if (XferEffect::IsSupportedMode(fMode)) { |
| 1384 if (NULL != effect) { | 1384 if (effect) { |
| 1385 *effect = XferEffect::Create(fMode, background); | 1385 *effect = XferEffect::Create(fMode, background); |
| 1386 SkASSERT(NULL != *effect); | 1386 SkASSERT(*effect); |
| 1387 } | 1387 } |
| 1388 return true; | 1388 return true; |
| 1389 } | 1389 } |
| 1390 return false; | 1390 return false; |
| 1391 } | 1391 } |
| 1392 #endif | 1392 #endif |
| 1393 | 1393 |
| 1394 const char* SkXfermode::ModeName(Mode mode) { | 1394 const char* SkXfermode::ModeName(Mode mode) { |
| 1395 SkASSERT((unsigned) mode <= (unsigned)kLastMode); | 1395 SkASSERT((unsigned) mode <= (unsigned)kLastMode); |
| 1396 const char* gModeStrings[] = { | 1396 const char* gModeStrings[] = { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1587 }; | 1587 }; |
| 1588 | 1588 |
| 1589 void SkDstInXfermode::xfer32(SkPMColor* SK_RESTRICT dst, | 1589 void SkDstInXfermode::xfer32(SkPMColor* SK_RESTRICT dst, |
| 1590 const SkPMColor* SK_RESTRICT src, int count, | 1590 const SkPMColor* SK_RESTRICT src, int count, |
| 1591 const SkAlpha* SK_RESTRICT aa) const { | 1591 const SkAlpha* SK_RESTRICT aa) const { |
| 1592 SkASSERT(dst && src); | 1592 SkASSERT(dst && src); |
| 1593 | 1593 |
| 1594 if (count <= 0) { | 1594 if (count <= 0) { |
| 1595 return; | 1595 return; |
| 1596 } | 1596 } |
| 1597 if (NULL != aa) { | 1597 if (aa) { |
| 1598 return this->INHERITED::xfer32(dst, src, count, aa); | 1598 return this->INHERITED::xfer32(dst, src, count, aa); |
| 1599 } | 1599 } |
| 1600 | 1600 |
| 1601 do { | 1601 do { |
| 1602 unsigned a = SkGetPackedA32(*src); | 1602 unsigned a = SkGetPackedA32(*src); |
| 1603 *dst = SkAlphaMulQ(*dst, SkAlpha255To256(a)); | 1603 *dst = SkAlphaMulQ(*dst, SkAlpha255To256(a)); |
| 1604 dst++; | 1604 dst++; |
| 1605 src++; | 1605 src++; |
| 1606 } while (--count != 0); | 1606 } while (--count != 0); |
| 1607 } | 1607 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1634 }; | 1634 }; |
| 1635 | 1635 |
| 1636 void SkDstOutXfermode::xfer32(SkPMColor* SK_RESTRICT dst, | 1636 void SkDstOutXfermode::xfer32(SkPMColor* SK_RESTRICT dst, |
| 1637 const SkPMColor* SK_RESTRICT src, int count, | 1637 const SkPMColor* SK_RESTRICT src, int count, |
| 1638 const SkAlpha* SK_RESTRICT aa) const { | 1638 const SkAlpha* SK_RESTRICT aa) const { |
| 1639 SkASSERT(dst && src); | 1639 SkASSERT(dst && src); |
| 1640 | 1640 |
| 1641 if (count <= 0) { | 1641 if (count <= 0) { |
| 1642 return; | 1642 return; |
| 1643 } | 1643 } |
| 1644 if (NULL != aa) { | 1644 if (aa) { |
| 1645 return this->INHERITED::xfer32(dst, src, count, aa); | 1645 return this->INHERITED::xfer32(dst, src, count, aa); |
| 1646 } | 1646 } |
| 1647 | 1647 |
| 1648 do { | 1648 do { |
| 1649 unsigned a = SkGetPackedA32(*src); | 1649 unsigned a = SkGetPackedA32(*src); |
| 1650 *dst = SkAlphaMulQ(*dst, SkAlpha255To256(255 - a)); | 1650 *dst = SkAlphaMulQ(*dst, SkAlpha255To256(255 - a)); |
| 1651 dst++; | 1651 dst++; |
| 1652 src++; | 1652 src++; |
| 1653 } while (--count != 0); | 1653 } while (--count != 0); |
| 1654 } | 1654 } |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1956 } else { | 1956 } else { |
| 1957 proc16 = rec.fProc16_General; | 1957 proc16 = rec.fProc16_General; |
| 1958 } | 1958 } |
| 1959 } | 1959 } |
| 1960 return proc16; | 1960 return proc16; |
| 1961 } | 1961 } |
| 1962 | 1962 |
| 1963 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) | 1963 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) |
| 1964 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) | 1964 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) |
| 1965 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1965 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |