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

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

Issue 864833002: Remove the need for asCoeff in SkXfermode. (Closed) Base URL: https://skia.googlesource.com/skia.git@moreXferCleanup
Patch Set: Fix build Created 5 years, 11 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 | « include/core/SkXfermode.h ('k') | src/core/SkPaintPriv.cpp » ('j') | 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 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDraw.h" 8 #include "SkDraw.h"
9 #include "SkBlitter.h" 9 #include "SkBlitter.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 929
930 static SkScalar fast_len(const SkVector& vec) { 930 static SkScalar fast_len(const SkVector& vec) {
931 SkScalar x = SkScalarAbs(vec.fX); 931 SkScalar x = SkScalarAbs(vec.fX);
932 SkScalar y = SkScalarAbs(vec.fY); 932 SkScalar y = SkScalarAbs(vec.fY);
933 if (x < y) { 933 if (x < y) {
934 SkTSwap(x, y); 934 SkTSwap(x, y);
935 } 935 }
936 return x + SkScalarHalf(y); 936 return x + SkScalarHalf(y);
937 } 937 }
938 938
939 static bool xfermodeSupportsCoverageAsAlpha(SkXfermode* xfer) {
940 SkXfermode::Coeff dc;
941 if (!SkXfermode::AsCoeff(xfer, NULL, &dc)) {
942 return false;
943 }
944
945 switch (dc) {
946 case SkXfermode::kOne_Coeff:
947 case SkXfermode::kISA_Coeff:
948 case SkXfermode::kISC_Coeff:
949 return true;
950 default:
951 return false;
952 }
953 }
954
955 bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix& matrix, 939 bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix& matrix,
956 SkScalar* coverage) { 940 SkScalar* coverage) {
957 SkASSERT(strokeWidth > 0); 941 SkASSERT(strokeWidth > 0);
958 // We need to try to fake a thick-stroke with a modulated hairline. 942 // We need to try to fake a thick-stroke with a modulated hairline.
959 943
960 if (matrix.hasPerspective()) { 944 if (matrix.hasPerspective()) {
961 return false; 945 return false;
962 } 946 }
963 947
964 SkVector src[2], dst[2]; 948 SkVector src[2], dst[2];
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 // at this point we're done with prePathMatrix 1040 // at this point we're done with prePathMatrix
1057 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) 1041 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;)
1058 1042
1059 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); 1043 SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
1060 1044
1061 { 1045 {
1062 SkScalar coverage; 1046 SkScalar coverage;
1063 if (SkDrawTreatAsHairline(origPaint, *matrix, &coverage)) { 1047 if (SkDrawTreatAsHairline(origPaint, *matrix, &coverage)) {
1064 if (SK_Scalar1 == coverage) { 1048 if (SK_Scalar1 == coverage) {
1065 paint.writable()->setStrokeWidth(0); 1049 paint.writable()->setStrokeWidth(0);
1066 } else if (xfermodeSupportsCoverageAsAlpha(origPaint.getXfermode())) { 1050 } else if (SkXfermode::SupportsCoverageAsAlpha(origPaint.getXfermode ())) {
1067 U8CPU newAlpha; 1051 U8CPU newAlpha;
1068 #if 0 1052 #if 0
1069 newAlpha = SkToU8(SkScalarRoundToInt(coverage * 1053 newAlpha = SkToU8(SkScalarRoundToInt(coverage *
1070 origPaint.getAlpha())); 1054 origPaint.getAlpha()));
1071 #else 1055 #else
1072 // this is the old technique, which we preserve for now so 1056 // this is the old technique, which we preserve for now so
1073 // we don't change previous results (testing) 1057 // we don't change previous results (testing)
1074 // the new way seems fine, its just (a tiny bit) different 1058 // the new way seems fine, its just (a tiny bit) different
1075 int scale = (int)SkScalarMul(coverage, 256); 1059 int scale = (int)SkScalarMul(coverage, 256);
1076 newAlpha = origPaint.getAlpha() * scale >> 8; 1060 newAlpha = origPaint.getAlpha() * scale >> 8;
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after
2398 mask->fImage = SkMask::AllocImage(size); 2382 mask->fImage = SkMask::AllocImage(size);
2399 memset(mask->fImage, 0, mask->computeImageSize()); 2383 memset(mask->fImage, 0, mask->computeImageSize());
2400 } 2384 }
2401 2385
2402 if (SkMask::kJustComputeBounds_CreateMode != mode) { 2386 if (SkMask::kJustComputeBounds_CreateMode != mode) {
2403 draw_into_mask(*mask, devPath, style); 2387 draw_into_mask(*mask, devPath, style);
2404 } 2388 }
2405 2389
2406 return true; 2390 return true;
2407 } 2391 }
OLDNEW
« no previous file with comments | « include/core/SkXfermode.h ('k') | src/core/SkPaintPriv.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698