OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
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 "Sk4fLinearGradient.h" | 8 #include "Sk4fLinearGradient.h" |
9 #include "SkLinearGradient.h" | 9 #include "SkLinearGradient.h" |
10 | 10 |
11 // define to test the 4f gradient path | 11 // define to test the 4f gradient path |
12 // #define USE_4fGRADIENTS | 12 // #define FORCE_4F_CONTEXT |
13 | 13 |
14 static const float kInv255Float = 1.0f / 255; | 14 static const float kInv255Float = 1.0f / 255; |
15 | 15 |
16 static inline int repeat_8bits(int x) { | 16 static inline int repeat_8bits(int x) { |
17 return x & 0xFF; | 17 return x & 0xFF; |
18 } | 18 } |
19 | 19 |
20 // Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly. | 20 // Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly. |
21 // See http://code.google.com/p/skia/issues/detail?id=472 | 21 // See http://code.google.com/p/skia/issues/detail?id=472 |
22 #if defined(_MSC_VER) && (_MSC_VER >= 1600) | 22 #if defined(_MSC_VER) && (_MSC_VER >= 1600) |
(...skipping 17 matching lines...) Expand all Loading... |
40 SkScalar inv = mag ? SkScalarInvert(mag) : 0; | 40 SkScalar inv = mag ? SkScalarInvert(mag) : 0; |
41 | 41 |
42 vec.scale(inv); | 42 vec.scale(inv); |
43 SkMatrix matrix; | 43 SkMatrix matrix; |
44 matrix.setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY); | 44 matrix.setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY); |
45 matrix.postTranslate(-pts[0].fX, -pts[0].fY); | 45 matrix.postTranslate(-pts[0].fX, -pts[0].fY); |
46 matrix.postScale(inv, inv); | 46 matrix.postScale(inv, inv); |
47 return matrix; | 47 return matrix; |
48 } | 48 } |
49 | 49 |
50 static bool use_4f_context(uint32_t flags) { | 50 static bool use_4f_context(const SkShader::ContextRec& rec, uint32_t flags) { |
51 #ifdef USE_4fGRADIENTS | 51 #ifdef FORCE_4F_CONTEXT |
52 return true; | 52 return true; |
53 #else | 53 #else |
54 return SkToBool(flags & SkLinearGradient::kForce4fContext_PrivateFlag); | 54 // Perspective not supported in 4f yet. |
| 55 if (rec.fMatrix->hasPerspective() |
| 56 || (rec.fLocalMatrix && rec.fLocalMatrix->hasPerspective())) { |
| 57 return false; |
| 58 } |
| 59 |
| 60 return rec.fPreferredDstType == SkShader::ContextRec::kPM4f_DstType |
| 61 || SkToBool(flags & SkLinearGradient::kForce4fContext_PrivateFlag); |
55 #endif | 62 #endif |
56 } | 63 } |
57 | 64 |
58 /////////////////////////////////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////////////////////////////////// |
59 | 66 |
60 SkLinearGradient::SkLinearGradient(const SkPoint pts[2], const Descriptor& desc) | 67 SkLinearGradient::SkLinearGradient(const SkPoint pts[2], const Descriptor& desc) |
61 : SkGradientShaderBase(desc, pts_to_unit_matrix(pts)) | 68 : SkGradientShaderBase(desc, pts_to_unit_matrix(pts)) |
62 , fStart(pts[0]) | 69 , fStart(pts[0]) |
63 , fEnd(pts[1]) { | 70 , fEnd(pts[1]) { |
64 } | 71 } |
65 | 72 |
66 SkFlattenable* SkLinearGradient::CreateProc(SkReadBuffer& buffer) { | 73 SkFlattenable* SkLinearGradient::CreateProc(SkReadBuffer& buffer) { |
67 DescriptorScope desc; | 74 DescriptorScope desc; |
68 if (!desc.unflatten(buffer)) { | 75 if (!desc.unflatten(buffer)) { |
69 return nullptr; | 76 return nullptr; |
70 } | 77 } |
71 SkPoint pts[2]; | 78 SkPoint pts[2]; |
72 pts[0] = buffer.readPoint(); | 79 pts[0] = buffer.readPoint(); |
73 pts[1] = buffer.readPoint(); | 80 pts[1] = buffer.readPoint(); |
74 return SkGradientShader::CreateLinear(pts, desc.fColors, desc.fPos, desc.fCo
unt, | 81 return SkGradientShader::CreateLinear(pts, desc.fColors, desc.fPos, desc.fCo
unt, |
75 desc.fTileMode, desc.fGradFlags, desc.
fLocalMatrix); | 82 desc.fTileMode, desc.fGradFlags, desc.
fLocalMatrix); |
76 } | 83 } |
77 | 84 |
78 void SkLinearGradient::flatten(SkWriteBuffer& buffer) const { | 85 void SkLinearGradient::flatten(SkWriteBuffer& buffer) const { |
79 this->INHERITED::flatten(buffer); | 86 this->INHERITED::flatten(buffer); |
80 buffer.writePoint(fStart); | 87 buffer.writePoint(fStart); |
81 buffer.writePoint(fEnd); | 88 buffer.writePoint(fEnd); |
82 } | 89 } |
83 | 90 |
84 size_t SkLinearGradient::contextSize(const ContextRec&) const { | 91 size_t SkLinearGradient::contextSize(const ContextRec& rec) const { |
85 return use_4f_context(fGradFlags) | 92 return use_4f_context(rec, fGradFlags) |
86 ? sizeof(LinearGradient4fContext) | 93 ? sizeof(LinearGradient4fContext) |
87 : sizeof(LinearGradientContext); | 94 : sizeof(LinearGradientContext); |
88 } | 95 } |
89 | 96 |
90 SkShader::Context* SkLinearGradient::onCreateContext(const ContextRec& rec, void
* storage) const { | 97 SkShader::Context* SkLinearGradient::onCreateContext(const ContextRec& rec, void
* storage) const { |
91 return use_4f_context(fGradFlags) | 98 return use_4f_context(rec, fGradFlags) |
92 ? static_cast<SkShader::Context*>(new (storage) LinearGradient4fContext(
*this, rec)) | 99 ? static_cast<SkShader::Context*>(new (storage) LinearGradient4fContext(
*this, rec)) |
93 : static_cast<SkShader::Context*>(new (storage) LinearGradientContext(*t
his, rec)); | 100 : static_cast<SkShader::Context*>(new (storage) LinearGradientContext(*t
his, rec)); |
94 } | 101 } |
95 | 102 |
96 // This swizzles SkColor into the same component order as SkPMColor, but does no
t actually | 103 // This swizzles SkColor into the same component order as SkPMColor, but does no
t actually |
97 // "pre" multiply the color components. | 104 // "pre" multiply the color components. |
98 // | 105 // |
99 // This allows us to map directly to Sk4f, and eventually scale down to bytes to
output a | 106 // This allows us to map directly to Sk4f, and eventually scale down to bytes to
output a |
100 // SkPMColor from the floats, without having to swizzle each time. | 107 // SkPMColor from the floats, without having to swizzle each time. |
101 // | 108 // |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe
r); | 762 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe
r); |
756 } | 763 } |
757 } else { | 764 } else { |
758 if (fApplyAlphaAfterInterp) { | 765 if (fApplyAlphaAfterInterp) { |
759 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe
r); | 766 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe
r); |
760 } else { | 767 } else { |
761 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith
er); | 768 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith
er); |
762 } | 769 } |
763 } | 770 } |
764 } | 771 } |
OLD | NEW |