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

Side by Side Diff: src/core/SkXfermode.cpp

Issue 1060493002: Exclusion and Difference modes using Sk4f (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "SkXfermode.h" 9 #include "SkXfermode.h"
10 #include "SkXfermode_opts_SSE2.h" 10 #include "SkXfermode_opts_SSE2.h"
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 } 1194 }
1195 1195
1196 static Sk4f clamp_255(const Sk4f& value) { 1196 static Sk4f clamp_255(const Sk4f& value) {
1197 return Sk4f::Min(Sk4f(255), value); 1197 return Sk4f::Min(Sk4f(255), value);
1198 } 1198 }
1199 1199
1200 static Sk4f clamp_0_255(const Sk4f& value) { 1200 static Sk4f clamp_0_255(const Sk4f& value) {
1201 return Sk4f::Max(Sk4f(0), Sk4f::Min(Sk4f(255), value)); 1201 return Sk4f::Max(Sk4f(0), Sk4f::Min(Sk4f(255), value));
1202 } 1202 }
1203 1203
1204 // return a swizzle of a | rgb
1205 static Sk4f set_a_rgb(const Sk4f& a, const Sk4f& rgb) {
1206 SkPMFloat pma = a;
1207 SkPMFloat pmc = rgb;
1208 return SkPMFloat(pma.a(), pmc.r(), pmc.g(), pmc.b());
mtklein 2015/04/03 13:23:58 Boy, this is annoying. We can make this operation
mtklein 2015/04/03 13:35:47 Well, maybe it's not so annoying. On x86 this can
1209 }
1210
1204 /** 1211 /**
1205 * Some modes can, due to very slight numerical error, generate "invalid" pmcol ors... 1212 * Some modes can, due to very slight numerical error, generate "invalid" pmcol ors...
1206 * 1213 *
1207 * e.g. 1214 * e.g.
1208 * alpha = 100.9999 1215 * alpha = 100.9999
1209 * red = 101 1216 * red = 101
1210 * 1217 *
1211 * or 1218 * or
1212 * alpha = 255.0001 1219 * alpha = 255.0001
1213 * 1220 *
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 Sk4f sc = src; 1311 Sk4f sc = src;
1305 Sk4f dc = dst; 1312 Sk4f dc = dst;
1306 Sk4f rc = sc + dc + (sc * (dc - da) - dc * sa) * inv255; 1313 Sk4f rc = sc + dc + (sc * (dc - da) - dc * sa) * inv255;
1307 // ra = srcover(sa, da), but the calc for rc happens to accomplish this for us 1314 // ra = srcover(sa, da), but the calc for rc happens to accomplish this for us
1308 return check_as_pmfloat(clamp_0_255(rc)); 1315 return check_as_pmfloat(clamp_0_255(rc));
1309 } 1316 }
1310 static const bool kFoldCoverageIntoSrcAlpha = false; 1317 static const bool kFoldCoverageIntoSrcAlpha = false;
1311 static const SkXfermode::Mode kMode = SkXfermode::kMultiply_Mode; 1318 static const SkXfermode::Mode kMode = SkXfermode::kMultiply_Mode;
1312 }; 1319 };
1313 1320
1321 struct Difference4f {
1322 static SkPMFloat Xfer(const SkPMFloat& src, const SkPMFloat& dst) {
1323 const Sk4f inv255(gInv255);
1324 Sk4f sa = Sk4f(src.a());
1325 Sk4f da = Sk4f(dst.a());
1326 Sk4f sc = src;
1327 Sk4f dc = dst;
1328 Sk4f min = Sk4f::Min(sc * da, dc * sa) * inv255;
1329 Sk4f ra = sc + dc - min;
1330 return check_as_pmfloat(set_a_rgb(ra, ra - min));
1331 }
1332 static const bool kFoldCoverageIntoSrcAlpha = false;
1333 static const SkXfermode::Mode kMode = SkXfermode::kDifference_Mode;
1334 };
1335
1336 struct Exclusion4f {
1337 static SkPMFloat Xfer(const SkPMFloat& src, const SkPMFloat& dst) {
1338 const Sk4f inv255(gInv255);
1339 Sk4f sc = src;
1340 Sk4f dc = dst;
1341 Sk4f prod = sc * dc * inv255;
1342 Sk4f ra = sc + dc - prod;
1343 return check_as_pmfloat(set_a_rgb(ra, ra - prod));
1344 }
1345 static const bool kFoldCoverageIntoSrcAlpha = false;
1346 static const SkXfermode::Mode kMode = SkXfermode::kExclusion_Mode;
1347 };
1348
1314 template <typename ProcType> 1349 template <typename ProcType>
1315 class SkT4fXfermode : public SkProcCoeffXfermode { 1350 class SkT4fXfermode : public SkProcCoeffXfermode {
1316 public: 1351 public:
1317 static SkXfermode* Create(const ProcCoeff& rec) { 1352 static SkXfermode* Create(const ProcCoeff& rec) {
1318 return SkNEW_ARGS(SkT4fXfermode, (rec)); 1353 return SkNEW_ARGS(SkT4fXfermode, (rec));
1319 } 1354 }
1320 1355
1321 void xfer32(SkPMColor dst[], const SkPMColor src[], int n, const SkAlpha aa[ ]) const override { 1356 void xfer32(SkPMColor dst[], const SkPMColor src[], int n, const SkAlpha aa[ ]) const override {
1322 if (NULL == aa) { 1357 if (NULL == aa) {
1323 while (n & 3) { 1358 while (n & 3) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 break; 1473 break;
1439 case SkXfermode::kModulate_Mode: 1474 case SkXfermode::kModulate_Mode:
1440 xfer = SkT4fXfermode<Modulate4f>::Create(rec); 1475 xfer = SkT4fXfermode<Modulate4f>::Create(rec);
1441 break; 1476 break;
1442 case SkXfermode::kScreen_Mode: 1477 case SkXfermode::kScreen_Mode:
1443 xfer = SkT4fXfermode<Screen4f>::Create(rec); 1478 xfer = SkT4fXfermode<Screen4f>::Create(rec);
1444 break; 1479 break;
1445 case SkXfermode::kMultiply_Mode: 1480 case SkXfermode::kMultiply_Mode:
1446 xfer = SkT4fXfermode<Multiply4f>::Create(rec); 1481 xfer = SkT4fXfermode<Multiply4f>::Create(rec);
1447 break; 1482 break;
1483 case SkXfermode::kDifference_Mode:
1484 xfer = SkT4fXfermode<Difference4f>::Create(rec);
1485 break;
1486 case SkXfermode::kExclusion_Mode:
1487 xfer = SkT4fXfermode<Exclusion4f>::Create(rec);
1488 break;
1448 default: 1489 default:
1449 break; 1490 break;
1450 } 1491 }
1451 if (xfer) { 1492 if (xfer) {
1452 return xfer; 1493 return xfer;
1453 } 1494 }
1454 #endif 1495 #endif
1455 1496
1456 // check if we have a platform optim for that 1497 // check if we have a platform optim for that
1457 SkProcCoeffXfermode* xfm = SkPlatformXfermodeFactory(rec, mode); 1498 SkProcCoeffXfermode* xfm = SkPlatformXfermodeFactory(rec, mode);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 } else { 1785 } else {
1745 proc16 = rec.fProc16_General; 1786 proc16 = rec.fProc16_General;
1746 } 1787 }
1747 } 1788 }
1748 return proc16; 1789 return proc16;
1749 } 1790 }
1750 1791
1751 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) 1792 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode)
1752 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) 1793 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode)
1753 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1794 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698