| OLD | NEW |
| 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 #define __STDC_LIMIT_MACROS | 7 #define __STDC_LIMIT_MACROS |
| 8 | 8 |
| 9 #include "SkDraw.h" | 9 #include "SkDraw.h" |
| 10 #include "SkBlendModePriv.h" |
| 10 #include "SkBlitter.h" | 11 #include "SkBlitter.h" |
| 11 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 12 #include "SkColorPriv.h" | 13 #include "SkColorPriv.h" |
| 13 #include "SkDevice.h" | 14 #include "SkDevice.h" |
| 14 #include "SkDeviceLooper.h" | 15 #include "SkDeviceLooper.h" |
| 15 #include "SkFindAndPlaceGlyph.h" | 16 #include "SkFindAndPlaceGlyph.h" |
| 16 #include "SkFixed.h" | 17 #include "SkFixed.h" |
| 17 #include "SkMaskFilter.h" | 18 #include "SkMaskFilter.h" |
| 18 #include "SkMatrix.h" | 19 #include "SkMatrix.h" |
| 19 #include "SkPaint.h" | 20 #include "SkPaint.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 157 } |
| 157 | 158 |
| 158 static BitmapXferProc ChooseBitmapXferProc(const SkPixmap& dst, const SkPaint& p
aint, | 159 static BitmapXferProc ChooseBitmapXferProc(const SkPixmap& dst, const SkPaint& p
aint, |
| 159 uint32_t* data) { | 160 uint32_t* data) { |
| 160 // todo: we can apply colorfilter up front if no shader, so we wouldn't | 161 // todo: we can apply colorfilter up front if no shader, so we wouldn't |
| 161 // need to abort this fastpath | 162 // need to abort this fastpath |
| 162 if (paint.getShader() || paint.getColorFilter()) { | 163 if (paint.getShader() || paint.getColorFilter()) { |
| 163 return nullptr; | 164 return nullptr; |
| 164 } | 165 } |
| 165 | 166 |
| 166 SkXfermode::Mode mode; | 167 SkBlendMode mode = paint.getBlendMode(); |
| 167 if (!SkXfermode::AsMode(paint.getXfermode(), &mode)) { | |
| 168 return nullptr; | |
| 169 } | |
| 170 | |
| 171 SkColor color = paint.getColor(); | 168 SkColor color = paint.getColor(); |
| 172 | 169 |
| 173 // collaps modes based on color... | 170 // collaps modes based on color... |
| 174 if (SkXfermode::kSrcOver_Mode == mode) { | 171 if (SkBlendMode::kSrcOver == mode) { |
| 175 unsigned alpha = SkColorGetA(color); | 172 unsigned alpha = SkColorGetA(color); |
| 176 if (0 == alpha) { | 173 if (0 == alpha) { |
| 177 mode = SkXfermode::kDst_Mode; | 174 mode = SkBlendMode::kDst; |
| 178 } else if (0xFF == alpha) { | 175 } else if (0xFF == alpha) { |
| 179 mode = SkXfermode::kSrc_Mode; | 176 mode = SkBlendMode::kSrc; |
| 180 } | 177 } |
| 181 } | 178 } |
| 182 | 179 |
| 183 switch (mode) { | 180 switch (mode) { |
| 184 case SkXfermode::kClear_Mode: | 181 case SkBlendMode::kClear: |
| 185 // SkDebugf("--- D_Clear_BitmapXferProc\n"); | 182 // SkDebugf("--- D_Clear_BitmapXferProc\n"); |
| 186 return D_Clear_BitmapXferProc; // ignore data | 183 return D_Clear_BitmapXferProc; // ignore data |
| 187 case SkXfermode::kDst_Mode: | 184 case SkBlendMode::kDst: |
| 188 // SkDebugf("--- D_Dst_BitmapXferProc\n"); | 185 // SkDebugf("--- D_Dst_BitmapXferProc\n"); |
| 189 return D_Dst_BitmapXferProc; // ignore data | 186 return D_Dst_BitmapXferProc; // ignore data |
| 190 case SkXfermode::kSrc_Mode: { | 187 case SkBlendMode::kSrc: { |
| 191 /* | 188 /* |
| 192 should I worry about dithering for the lower depths? | 189 should I worry about dithering for the lower depths? |
| 193 */ | 190 */ |
| 194 SkPMColor pmc = SkPreMultiplyColor(color); | 191 SkPMColor pmc = SkPreMultiplyColor(color); |
| 195 switch (dst.colorType()) { | 192 switch (dst.colorType()) { |
| 196 case kN32_SkColorType: | 193 case kN32_SkColorType: |
| 197 if (data) { | 194 if (data) { |
| 198 *data = pmc; | 195 *data = pmc; |
| 199 } | 196 } |
| 200 // SkDebugf("--- D32_Src_BitmapXferProc\n"); | 197 // SkDebugf("--- D32_Src_BitmapXferProc\n"); |
| (...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 // at this point we're done with prePathMatrix | 1133 // at this point we're done with prePathMatrix |
| 1137 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) | 1134 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) |
| 1138 | 1135 |
| 1139 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); | 1136 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); |
| 1140 | 1137 |
| 1141 { | 1138 { |
| 1142 SkScalar coverage; | 1139 SkScalar coverage; |
| 1143 if (SkDrawTreatAsHairline(origPaint, *matrix, &coverage)) { | 1140 if (SkDrawTreatAsHairline(origPaint, *matrix, &coverage)) { |
| 1144 if (SK_Scalar1 == coverage) { | 1141 if (SK_Scalar1 == coverage) { |
| 1145 paint.writable()->setStrokeWidth(0); | 1142 paint.writable()->setStrokeWidth(0); |
| 1146 } else if (SkXfermode::SupportsCoverageAsAlpha(origPaint.getXfermode
())) { | 1143 } else if (SkBlendMode_SupportsCoverageAsAlpha(origPaint.getBlendMod
e())) { |
| 1147 U8CPU newAlpha; | 1144 U8CPU newAlpha; |
| 1148 #if 0 | 1145 #if 0 |
| 1149 newAlpha = SkToU8(SkScalarRoundToInt(coverage * | 1146 newAlpha = SkToU8(SkScalarRoundToInt(coverage * |
| 1150 origPaint.getAlpha())); | 1147 origPaint.getAlpha())); |
| 1151 #else | 1148 #else |
| 1152 // this is the old technique, which we preserve for now so | 1149 // this is the old technique, which we preserve for now so |
| 1153 // we don't change previous results (testing) | 1150 // we don't change previous results (testing) |
| 1154 // the new way seems fine, its just (a tiny bit) different | 1151 // the new way seems fine, its just (a tiny bit) different |
| 1155 int scale = (int)SkScalarMul(coverage, 256); | 1152 int scale = (int)SkScalarMul(coverage, 256); |
| 1156 newAlpha = origPaint.getAlpha() * scale >> 8; | 1153 newAlpha = origPaint.getAlpha() * scale >> 8; |
| (...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2109 mask->fImage = SkMask::AllocImage(size); | 2106 mask->fImage = SkMask::AllocImage(size); |
| 2110 memset(mask->fImage, 0, mask->computeImageSize()); | 2107 memset(mask->fImage, 0, mask->computeImageSize()); |
| 2111 } | 2108 } |
| 2112 | 2109 |
| 2113 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2110 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
| 2114 draw_into_mask(*mask, devPath, style); | 2111 draw_into_mask(*mask, devPath, style); |
| 2115 } | 2112 } |
| 2116 | 2113 |
| 2117 return true; | 2114 return true; |
| 2118 } | 2115 } |
| OLD | NEW |