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

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

Issue 1061193003: simplify xfers (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());
1209 }
1210
1211 /** 1204 /**
1212 * Some modes can, due to very slight numerical error, generate "invalid" pmcol ors... 1205 * Some modes can, due to very slight numerical error, generate "invalid" pmcol ors...
1213 * 1206 *
1214 * e.g. 1207 * e.g.
1215 * alpha = 100.9999 1208 * alpha = 100.9999
1216 * red = 101 1209 * red = 101
1217 * 1210 *
1218 * or 1211 * or
1219 * alpha = 255.0001 1212 * alpha = 255.0001
1220 * 1213 *
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 1301
1309 struct Difference4f { 1302 struct Difference4f {
1310 static SkPMFloat Xfer(const SkPMFloat& src, const SkPMFloat& dst) { 1303 static SkPMFloat Xfer(const SkPMFloat& src, const SkPMFloat& dst) {
1311 const Sk4f inv255(gInv255); 1304 const Sk4f inv255(gInv255);
1312 Sk4f sa = Sk4f(src.a()); 1305 Sk4f sa = Sk4f(src.a());
1313 Sk4f da = Sk4f(dst.a()); 1306 Sk4f da = Sk4f(dst.a());
1314 Sk4f sc = src; 1307 Sk4f sc = src;
1315 Sk4f dc = dst; 1308 Sk4f dc = dst;
1316 Sk4f min = Sk4f::Min(sc * da, dc * sa) * inv255; 1309 Sk4f min = Sk4f::Min(sc * da, dc * sa) * inv255;
1317 Sk4f ra = sc + dc - min; 1310 Sk4f ra = sc + dc - min;
1318 return check_as_pmfloat(set_a_rgb(ra, ra - min)); 1311 return check_as_pmfloat(ra - min * SkPMFloat(0, 1, 1, 1));
1319 } 1312 }
1320 static const bool kFoldCoverageIntoSrcAlpha = false; 1313 static const bool kFoldCoverageIntoSrcAlpha = false;
1321 static const SkXfermode::Mode kMode = SkXfermode::kDifference_Mode; 1314 static const SkXfermode::Mode kMode = SkXfermode::kDifference_Mode;
1322 }; 1315 };
1323 1316
1324 struct Exclusion4f { 1317 struct Exclusion4f {
1325 static SkPMFloat Xfer(const SkPMFloat& src, const SkPMFloat& dst) { 1318 static SkPMFloat Xfer(const SkPMFloat& src, const SkPMFloat& dst) {
1326 const Sk4f inv255(gInv255); 1319 const Sk4f inv255(gInv255);
1327 Sk4f sc = src; 1320 Sk4f sc = src;
1328 Sk4f dc = dst; 1321 Sk4f dc = dst;
1329 Sk4f prod = sc * dc * inv255; 1322 Sk4f prod = sc * dc * inv255;
1330 Sk4f ra = sc + dc - prod; 1323 Sk4f ra = sc + dc - prod;
1331 return check_as_pmfloat(set_a_rgb(ra, ra - prod)); 1324 return check_as_pmfloat(ra - prod * SkPMFloat(0, 1, 1, 1));
1332 } 1325 }
1333 static const bool kFoldCoverageIntoSrcAlpha = false; 1326 static const bool kFoldCoverageIntoSrcAlpha = false;
1334 static const SkXfermode::Mode kMode = SkXfermode::kExclusion_Mode; 1327 static const SkXfermode::Mode kMode = SkXfermode::kExclusion_Mode;
1335 }; 1328 };
1336 1329
1337 template <typename ProcType> 1330 template <typename ProcType>
1338 class SkT4fXfermode : public SkProcCoeffXfermode { 1331 class SkT4fXfermode : public SkProcCoeffXfermode {
1339 public: 1332 public:
1340 static SkXfermode* Create(const ProcCoeff& rec) { 1333 static SkXfermode* Create(const ProcCoeff& rec) {
1341 return SkNEW_ARGS(SkT4fXfermode, (rec)); 1334 return SkNEW_ARGS(SkT4fXfermode, (rec));
1342 } 1335 }
1343 1336
1344 void xfer32(SkPMColor dst[], const SkPMColor src[], int n, const SkAlpha aa[ ]) const override { 1337 void xfer32(SkPMColor dst[], const SkPMColor src[], int n, const SkAlpha aa[ ]) const override {
1345 if (NULL == aa) { 1338 if (NULL == aa) {
1346 while (n & 3) {
1347 *dst = ProcType::Xfer(SkPMFloat(*src++), SkPMFloat(*dst)).round( );
1348 dst++;
1349 n -= 1;
1350 }
1351 n >>= 2;
1352 for (int i = 0; i < n; ++i) { 1339 for (int i = 0; i < n; ++i) {
1353 SkPMFloat s0, s1, s2, s3; 1340 dst[i] = ProcType::Xfer(SkPMFloat(src[i]), SkPMFloat(dst[i])).ro und();
1354 SkPMFloat::From4PMColors(src, &s0, &s1, &s2, &s3);
1355 SkPMFloat d0, d1, d2, d3;
1356 SkPMFloat::From4PMColors(dst, &d0, &d1, &d2, &d3);
1357 SkPMFloat::RoundTo4PMColors(ProcType::Xfer(s0, d0), ProcType::Xf er(s1, d1),
1358 ProcType::Xfer(s2, d2), ProcType::Xf er(s3, d3), dst);
1359 src += 4;
1360 dst += 4;
1361 } 1341 }
1362 } else { 1342 } else {
1363 for (int i = 0; i < n; ++i) { 1343 for (int i = 0; i < n; ++i) {
1364 const Sk4f aa4 = Sk4f(aa[i] * gInv255); 1344 const Sk4f aa4 = Sk4f(aa[i] * gInv255);
1365 SkPMFloat dstF(dst[i]); 1345 SkPMFloat dstF(dst[i]);
1366 SkPMFloat srcF(src[i]); 1346 SkPMFloat srcF(src[i]);
1367 Sk4f res; 1347 Sk4f res;
1368 if (ProcType::kFoldCoverageIntoSrcAlpha) { 1348 if (ProcType::kFoldCoverageIntoSrcAlpha) {
1369 Sk4f src4 = srcF; 1349 Sk4f src4 = srcF;
1370 res = ProcType::Xfer(src4 * aa4, dstF); 1350 res = ProcType::Xfer(src4 * aa4, dstF);
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 } else { 1753 } else {
1774 proc16 = rec.fProc16_General; 1754 proc16 = rec.fProc16_General;
1775 } 1755 }
1776 } 1756 }
1777 return proc16; 1757 return proc16;
1778 } 1758 }
1779 1759
1780 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) 1760 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode)
1781 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) 1761 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode)
1782 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1762 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