fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Sk4fLinearGradient.h" |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 9 | #include "SkXfermode.h" |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 10 | |
| 11 | namespace { |
| 12 | |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 13 | template<DstType dstType, ApplyPremul premul> |
| 14 | void ramp(const Sk4f& c, const Sk4f& dc, typename DstTraits<dstType, premul>::Type dst[], int n) { |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 15 | SkASSERT(n > 0); |
| 16 | |
| 17 | const Sk4f dc2 = dc + dc; |
| 18 | const Sk4f dc4 = dc2 + dc2; |
| 19 | |
| 20 | Sk4f c0 = c ; |
| 21 | Sk4f c1 = c + dc; |
| 22 | Sk4f c2 = c0 + dc2; |
| 23 | Sk4f c3 = c1 + dc2; |
| 24 | |
| 25 | while (n >= 4) { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 26 | DstTraits<dstType, premul>::store4x(c0, c1, c2, c3, dst); |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 27 | dst += 4; |
| 28 | |
| 29 | c0 = c0 + dc4; |
| 30 | c1 = c1 + dc4; |
| 31 | c2 = c2 + dc4; |
| 32 | c3 = c3 + dc4; |
| 33 | n -= 4; |
| 34 | } |
| 35 | if (n & 2) { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 36 | DstTraits<dstType, premul>::store(c0, dst++); |
| 37 | DstTraits<dstType, premul>::store(c1, dst++); |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 38 | c0 = c0 + dc2; |
| 39 | } |
| 40 | if (n & 1) { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 41 | DstTraits<dstType, premul>::store(c0, dst); |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | template<SkShader::TileMode> |
| 46 | SkScalar pinFx(SkScalar); |
| 47 | |
| 48 | template<> |
| 49 | SkScalar pinFx<SkShader::kClamp_TileMode>(SkScalar fx) { |
| 50 | return fx; |
| 51 | } |
| 52 | |
| 53 | template<> |
| 54 | SkScalar pinFx<SkShader::kRepeat_TileMode>(SkScalar fx) { |
| 55 | const SkScalar f = SkScalarFraction(fx); |
| 56 | return f < 0 ? f + 1 : f; |
| 57 | } |
| 58 | |
| 59 | template<> |
| 60 | SkScalar pinFx<SkShader::kMirror_TileMode>(SkScalar fx) { |
| 61 | const SkScalar f = SkScalarMod(fx, 2.0f); |
| 62 | return f < 0 ? f + 2 : f; |
| 63 | } |
| 64 | |
fmalita | 7520fc4 | 2016-03-04 11:01:24 -0800 | [diff] [blame] | 65 | // true when x is in [k1,k2) |
| 66 | bool in_range(SkScalar x, SkScalar k1, SkScalar k2) { |
| 67 | SkASSERT(k1 != k2); |
| 68 | return (k1 < k2) |
| 69 | ? (x >= k1 && x < k2) |
| 70 | : (x >= k2 && x < k1); |
| 71 | } |
| 72 | |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 73 | } // anonymous namespace |
| 74 | |
| 75 | SkLinearGradient:: |
| 76 | LinearGradient4fContext::LinearGradient4fContext(const SkLinearGradient& shader, |
| 77 | const ContextRec& rec) |
fmalita | 7520fc4 | 2016-03-04 11:01:24 -0800 | [diff] [blame] | 78 | : INHERITED(shader, rec) { |
fmalita | 7520fc4 | 2016-03-04 11:01:24 -0800 | [diff] [blame] | 79 | |
fmalita | 7e6fcf8 | 2016-03-10 11:18:43 -0800 | [diff] [blame] | 80 | // Our fast path expects interval points to be monotonically increasing in x. |
| 81 | const bool reverseIntervals = this->isFast() && fDstToPos.getScaleX() < 0; |
| 82 | this->buildIntervals(shader, rec, reverseIntervals); |
fmalita | 7520fc4 | 2016-03-04 11:01:24 -0800 | [diff] [blame] | 83 | |
| 84 | SkASSERT(fIntervals.count() > 0); |
| 85 | fCachedInterval = fIntervals.begin(); |
| 86 | } |
| 87 | |
fmalita | 7520fc4 | 2016-03-04 11:01:24 -0800 | [diff] [blame] | 88 | const SkGradientShaderBase::GradientShaderBase4fContext::Interval* |
| 89 | SkLinearGradient::LinearGradient4fContext::findInterval(SkScalar fx) const { |
| 90 | SkASSERT(in_range(fx, fIntervals.front().fP0, fIntervals.back().fP1)); |
| 91 | |
| 92 | if (1) { |
| 93 | // Linear search, using the last scanline interval as a starting point. |
| 94 | SkASSERT(fCachedInterval >= fIntervals.begin()); |
| 95 | SkASSERT(fCachedInterval < fIntervals.end()); |
| 96 | const int search_dir = fDstToPos.getScaleX() >= 0 ? 1 : -1; |
| 97 | while (!in_range(fx, fCachedInterval->fP0, fCachedInterval->fP1)) { |
| 98 | fCachedInterval += search_dir; |
| 99 | if (fCachedInterval >= fIntervals.end()) { |
| 100 | fCachedInterval = fIntervals.begin(); |
| 101 | } else if (fCachedInterval < fIntervals.begin()) { |
| 102 | fCachedInterval = fIntervals.end() - 1; |
| 103 | } |
| 104 | } |
| 105 | return fCachedInterval; |
| 106 | } else { |
| 107 | // Binary search. Seems less effective than linear + caching. |
| 108 | const Interval* i0 = fIntervals.begin(); |
| 109 | const Interval* i1 = fIntervals.end() - 1; |
| 110 | |
| 111 | while (i0 != i1) { |
| 112 | SkASSERT(i0 < i1); |
| 113 | SkASSERT(in_range(fx, i0->fP0, i1->fP1)); |
| 114 | |
| 115 | const Interval* i = i0 + ((i1 - i0) >> 1); |
| 116 | |
| 117 | if (in_range(fx, i0->fP0, i->fP1)) { |
| 118 | i1 = i; |
| 119 | } else { |
| 120 | SkASSERT(in_range(fx, i->fP1, i1->fP1)); |
| 121 | i0 = i + 1; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | SkASSERT(in_range(fx, i0->fP0, i0->fP1)); |
| 126 | return i0; |
| 127 | } |
| 128 | } |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 129 | |
| 130 | void SkLinearGradient:: |
| 131 | LinearGradient4fContext::shadeSpan(int x, int y, SkPMColor dst[], int count) { |
fmalita | 7e6fcf8 | 2016-03-10 11:18:43 -0800 | [diff] [blame] | 132 | if (!this->isFast()) { |
| 133 | this->INHERITED::shadeSpan(x, y, dst, count); |
| 134 | return; |
| 135 | } |
| 136 | |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 137 | // TODO: plumb dithering |
| 138 | SkASSERT(count > 0); |
| 139 | if (fColorsArePremul) { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 140 | this->shadePremulSpan<DstType::L32, |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 141 | ApplyPremul::False>(x, y, dst, count); |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 142 | } else { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 143 | this->shadePremulSpan<DstType::L32, |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 144 | ApplyPremul::True>(x, y, dst, count); |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | void SkLinearGradient:: |
| 149 | LinearGradient4fContext::shadeSpan4f(int x, int y, SkPM4f dst[], int count) { |
fmalita | 7e6fcf8 | 2016-03-10 11:18:43 -0800 | [diff] [blame] | 150 | if (!this->isFast()) { |
| 151 | this->INHERITED::shadeSpan4f(x, y, dst, count); |
| 152 | return; |
| 153 | } |
| 154 | |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 155 | // TONOTDO: plumb dithering |
| 156 | SkASSERT(count > 0); |
| 157 | if (fColorsArePremul) { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 158 | this->shadePremulSpan<DstType::F32, |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 159 | ApplyPremul::False>(x, y, dst, count); |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 160 | } else { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 161 | this->shadePremulSpan<DstType::F32, |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 162 | ApplyPremul::True>(x, y, dst, count); |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 166 | template<DstType dstType, ApplyPremul premul> |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 167 | void SkLinearGradient:: |
| 168 | LinearGradient4fContext::shadePremulSpan(int x, int y, |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 169 | typename DstTraits<dstType, premul>::Type dst[], |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 170 | int count) const { |
| 171 | const SkLinearGradient& shader = |
| 172 | static_cast<const SkLinearGradient&>(fShader); |
| 173 | switch (shader.fTileMode) { |
| 174 | case kClamp_TileMode: |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 175 | this->shadeSpanInternal<dstType, |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 176 | premul, |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 177 | kClamp_TileMode>(x, y, dst, count); |
| 178 | break; |
| 179 | case kRepeat_TileMode: |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 180 | this->shadeSpanInternal<dstType, |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 181 | premul, |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 182 | kRepeat_TileMode>(x, y, dst, count); |
| 183 | break; |
| 184 | case kMirror_TileMode: |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 185 | this->shadeSpanInternal<dstType, |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 186 | premul, |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 187 | kMirror_TileMode>(x, y, dst, count); |
| 188 | break; |
| 189 | } |
| 190 | } |
| 191 | |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 192 | template<DstType dstType, ApplyPremul premul, SkShader::TileMode tileMode> |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 193 | void SkLinearGradient:: |
| 194 | LinearGradient4fContext::shadeSpanInternal(int x, int y, |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 195 | typename DstTraits<dstType, premul>::Type dst[], |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 196 | int count) const { |
| 197 | SkPoint pt; |
| 198 | fDstToPosProc(fDstToPos, |
| 199 | x + SK_ScalarHalf, |
| 200 | y + SK_ScalarHalf, |
| 201 | &pt); |
| 202 | const SkScalar fx = pinFx<tileMode>(pt.x()); |
| 203 | const SkScalar dx = fDstToPos.getScaleX(); |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 204 | LinearIntervalProcessor<dstType, tileMode> proc(fIntervals.begin(), |
| 205 | fIntervals.end() - 1, |
| 206 | this->findInterval(fx), |
| 207 | fx, |
| 208 | dx, |
| 209 | SkScalarNearlyZero(dx * count)); |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 210 | while (count > 0) { |
| 211 | // What we really want here is SkTPin(advance, 1, count) |
| 212 | // but that's a significant perf hit for >> stops; investigate. |
| 213 | const int n = SkScalarTruncToInt( |
| 214 | SkTMin<SkScalar>(proc.currentAdvance() + 1, SkIntToScalar(count))); |
| 215 | |
| 216 | // The current interval advance can be +inf (e.g. when reaching |
| 217 | // the clamp mode end intervals) - when that happens, we expect to |
| 218 | // a) consume all remaining count in one swoop |
| 219 | // b) return a zero color gradient |
| 220 | SkASSERT(SkScalarIsFinite(proc.currentAdvance()) |
| 221 | || (n == count && proc.currentRampIsZero())); |
| 222 | |
| 223 | if (proc.currentRampIsZero()) { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 224 | DstTraits<dstType, premul>::store(proc.currentColor(), |
| 225 | dst, n); |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 226 | } else { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 227 | ramp<dstType, premul>(proc.currentColor(), |
| 228 | proc.currentColorGrad(), |
| 229 | dst, n); |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | proc.advance(SkIntToScalar(n)); |
| 233 | count -= n; |
| 234 | dst += n; |
| 235 | } |
| 236 | } |
| 237 | |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 238 | template<DstType dstType, SkShader::TileMode tileMode> |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 239 | class SkLinearGradient:: |
| 240 | LinearGradient4fContext::LinearIntervalProcessor { |
| 241 | public: |
| 242 | LinearIntervalProcessor(const Interval* firstInterval, |
| 243 | const Interval* lastInterval, |
| 244 | const Interval* i, |
| 245 | SkScalar fx, |
| 246 | SkScalar dx, |
| 247 | bool is_vertical) |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 248 | : fAdvX((i->fP1 - fx) / dx) |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 249 | , fFirstInterval(firstInterval) |
| 250 | , fLastInterval(lastInterval) |
| 251 | , fInterval(i) |
| 252 | , fDx(dx) |
| 253 | , fIsVertical(is_vertical) |
| 254 | { |
| 255 | SkASSERT(firstInterval <= lastInterval); |
fmalita | 7e6fcf8 | 2016-03-10 11:18:43 -0800 | [diff] [blame] | 256 | SkASSERT(in_range(fx, i->fP0, i->fP1)); |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 257 | this->compute_interval_props(fx - i->fP0); |
| 258 | } |
| 259 | |
| 260 | SkScalar currentAdvance() const { |
| 261 | SkASSERT(fAdvX >= 0); |
| 262 | SkASSERT(fAdvX <= (fInterval->fP1 - fInterval->fP0) / fDx); |
| 263 | return fAdvX; |
| 264 | } |
| 265 | |
| 266 | bool currentRampIsZero() const { return fZeroRamp; } |
| 267 | const Sk4f& currentColor() const { return fCc; } |
| 268 | const Sk4f& currentColorGrad() const { return fDcDx; } |
| 269 | |
| 270 | void advance(SkScalar advX) { |
| 271 | SkASSERT(advX > 0); |
| 272 | SkASSERT(fAdvX >= 0); |
| 273 | |
| 274 | if (advX >= fAdvX) { |
| 275 | advX = this->advance_interval(advX); |
| 276 | } |
| 277 | SkASSERT(advX < fAdvX); |
| 278 | |
| 279 | fCc = fCc + fDcDx * Sk4f(advX); |
| 280 | fAdvX -= advX; |
| 281 | } |
| 282 | |
| 283 | private: |
| 284 | void compute_interval_props(SkScalar t) { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 285 | const Sk4f dC = DstTraits<dstType>::load(fInterval->fDc); |
| 286 | fCc = DstTraits<dstType>::load(fInterval->fC0); |
| 287 | fCc = fCc + dC * Sk4f(t); |
| 288 | fDcDx = dC * fDx; |
| 289 | fZeroRamp = fIsVertical || fInterval->isZeroRamp(); |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | const Interval* next_interval(const Interval* i) const { |
| 293 | SkASSERT(i >= fFirstInterval); |
| 294 | SkASSERT(i <= fLastInterval); |
| 295 | i++; |
| 296 | |
| 297 | if (tileMode == kClamp_TileMode) { |
| 298 | SkASSERT(i <= fLastInterval); |
| 299 | return i; |
| 300 | } |
| 301 | |
| 302 | return (i <= fLastInterval) ? i : fFirstInterval; |
| 303 | } |
| 304 | |
| 305 | SkScalar advance_interval(SkScalar advX) { |
| 306 | SkASSERT(advX >= fAdvX); |
| 307 | |
| 308 | do { |
| 309 | advX -= fAdvX; |
| 310 | fInterval = this->next_interval(fInterval); |
| 311 | fAdvX = (fInterval->fP1 - fInterval->fP0) / fDx; |
| 312 | SkASSERT(fAdvX > 0); |
| 313 | } while (advX >= fAdvX); |
| 314 | |
| 315 | compute_interval_props(0); |
| 316 | |
| 317 | SkASSERT(advX >= 0); |
| 318 | return advX; |
| 319 | } |
| 320 | |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 321 | // Current interval properties. |
fmalita | bc590c0 | 2016-02-22 09:12:33 -0800 | [diff] [blame] | 322 | Sk4f fDcDx; // dst color gradient (dc/dx) |
| 323 | Sk4f fCc; // current color, interpolated in dst |
| 324 | SkScalar fAdvX; // remaining interval advance in dst |
| 325 | bool fZeroRamp; // current interval color grad is 0 |
| 326 | |
| 327 | const Interval* fFirstInterval; |
| 328 | const Interval* fLastInterval; |
| 329 | const Interval* fInterval; // current interval |
| 330 | const SkScalar fDx; // 'dx' for consistency with other impls; actually dt/dx |
| 331 | const bool fIsVertical; |
| 332 | }; |
fmalita | 7e6fcf8 | 2016-03-10 11:18:43 -0800 | [diff] [blame] | 333 | |
| 334 | void SkLinearGradient:: |
| 335 | LinearGradient4fContext::mapTs(int x, int y, SkScalar ts[], int count) const { |
| 336 | SkASSERT(count > 0); |
| 337 | SkASSERT(fDstToPosClass != kLinear_MatrixClass); |
| 338 | |
| 339 | SkScalar sx = x + SK_ScalarHalf; |
| 340 | const SkScalar sy = y + SK_ScalarHalf; |
| 341 | SkPoint pt; |
| 342 | |
| 343 | if (fDstToPosClass != kPerspective_MatrixClass) { |
| 344 | // kLinear_MatrixClass, kFixedStepInX_MatrixClass => fixed dt per scanline |
| 345 | const SkScalar dtdx = fDstToPos.fixedStepInX(sy).x(); |
| 346 | fDstToPosProc(fDstToPos, sx, sy, &pt); |
| 347 | |
| 348 | const Sk4f dtdx4 = Sk4f(4 * dtdx); |
| 349 | Sk4f t4 = Sk4f(pt.x() + 0 * dtdx, |
| 350 | pt.x() + 1 * dtdx, |
| 351 | pt.x() + 2 * dtdx, |
| 352 | pt.x() + 3 * dtdx); |
| 353 | |
| 354 | while (count >= 4) { |
| 355 | t4.store(ts); |
| 356 | t4 = t4 + dtdx4; |
| 357 | ts += 4; |
| 358 | count -= 4; |
| 359 | } |
| 360 | |
| 361 | if (count & 2) { |
| 362 | *ts++ = t4[0]; |
| 363 | *ts++ = t4[1]; |
| 364 | t4 = SkNx_shuffle<2, 0, 1, 3>(t4); |
| 365 | } |
| 366 | |
| 367 | if (count & 1) { |
| 368 | *ts++ = t4[0]; |
| 369 | } |
| 370 | } else { |
| 371 | for (int i = 0; i < count; ++i) { |
| 372 | fDstToPosProc(fDstToPos, sx, sy, &pt); |
| 373 | ts[i] = pt.x(); |
| 374 | sx += SK_Scalar1; |
| 375 | } |
| 376 | } |
| 377 | } |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 378 | |
reed | 58fc94e | 2016-03-18 12:42:26 -0700 | [diff] [blame] | 379 | bool SkLinearGradient::LinearGradient4fContext::onChooseBlitProcs(const SkImageInfo& info, |
| 380 | BlitState* state) { |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 381 | SkXfermode::Mode mode; |
| 382 | if (!SkXfermode::AsMode(state->fXfer, &mode)) { |
reed | 58fc94e | 2016-03-18 12:42:26 -0700 | [diff] [blame] | 383 | return false; |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | const SkGradientShaderBase& shader = static_cast<const SkGradientShaderBase&>(fShader); |
| 387 | if (mode != SkXfermode::kSrc_Mode && |
| 388 | !(mode == SkXfermode::kSrcOver_Mode && shader.colorsAreOpaque())) { |
reed | 58fc94e | 2016-03-18 12:42:26 -0700 | [diff] [blame] | 389 | return false; |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | switch (info.colorType()) { |
| 393 | case kN32_SkColorType: |
reed | 58fc94e | 2016-03-18 12:42:26 -0700 | [diff] [blame] | 394 | state->fBlitBW = D32_BlitBW; |
| 395 | return true; |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 396 | case kRGBA_F16_SkColorType: |
reed | 58fc94e | 2016-03-18 12:42:26 -0700 | [diff] [blame] | 397 | state->fBlitBW = D64_BlitBW; |
| 398 | return true; |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 399 | default: |
reed | 58fc94e | 2016-03-18 12:42:26 -0700 | [diff] [blame] | 400 | return false; |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
| 404 | void SkLinearGradient:: |
reed | 58fc94e | 2016-03-18 12:42:26 -0700 | [diff] [blame] | 405 | LinearGradient4fContext::D32_BlitBW(BlitState* state, int x, int y, const SkPixmap& dst, |
| 406 | int count) { |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 407 | // FIXME: ignoring coverage for now |
| 408 | const LinearGradient4fContext* ctx = |
| 409 | static_cast<const LinearGradient4fContext*>(state->fCtx); |
| 410 | |
| 411 | if (dst.info().isLinear()) { |
| 412 | if (ctx->fColorsArePremul) { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 413 | ctx->shadePremulSpan<DstType::L32, ApplyPremul::False>( |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 414 | x, y, dst.writable_addr32(x, y), count); |
| 415 | } else { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 416 | ctx->shadePremulSpan<DstType::L32, ApplyPremul::True>( |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 417 | x, y, dst.writable_addr32(x, y), count); |
| 418 | } |
| 419 | } else { |
| 420 | if (ctx->fColorsArePremul) { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 421 | ctx->shadePremulSpan<DstType::S32, ApplyPremul::False>( |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 422 | x, y, dst.writable_addr32(x, y), count); |
| 423 | } else { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 424 | ctx->shadePremulSpan<DstType::S32, ApplyPremul::True>( |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 425 | x, y, dst.writable_addr32(x, y), count); |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | void SkLinearGradient:: |
reed | 58fc94e | 2016-03-18 12:42:26 -0700 | [diff] [blame] | 431 | LinearGradient4fContext::D64_BlitBW(BlitState* state, int x, int y, const SkPixmap& dst, |
| 432 | int count) { |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 433 | // FIXME: ignoring coverage for now |
| 434 | const LinearGradient4fContext* ctx = |
| 435 | static_cast<const LinearGradient4fContext*>(state->fCtx); |
| 436 | |
| 437 | if (ctx->fColorsArePremul) { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 438 | ctx->shadePremulSpan<DstType::F16, ApplyPremul::False>( |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 439 | x, y, dst.writable_addr64(x, y), count); |
| 440 | } else { |
fmalita | dc6c9bf | 2016-03-21 13:16:51 -0700 | [diff] [blame^] | 441 | ctx->shadePremulSpan<DstType::F16, ApplyPremul::True>( |
fmalita | a928b28 | 2016-03-18 10:28:23 -0700 | [diff] [blame] | 442 | x, y, dst.writable_addr64(x, y), count); |
| 443 | } |
| 444 | } |