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 "SkLinearGradient.h" | 8 #include "SkLinearGradient.h" |
9 | 9 |
10 static inline int repeat_bits(int x, const int bits) { | 10 static inline int repeat_bits(int x, const int bits) { |
(...skipping 21 matching lines...) Expand all Loading... |
32 if (x & 256) { | 32 if (x & 256) { |
33 x = ~x; | 33 x = ~x; |
34 } | 34 } |
35 return x & 255; | 35 return x & 255; |
36 } | 36 } |
37 | 37 |
38 #if defined(_MSC_VER) && (_MSC_VER >= 1600) | 38 #if defined(_MSC_VER) && (_MSC_VER >= 1600) |
39 #pragma optimize("", on) | 39 #pragma optimize("", on) |
40 #endif | 40 #endif |
41 | 41 |
42 static void pts_to_unit_matrix(const SkPoint pts[2], SkMatrix* matrix) { | 42 static SkMatrix pts_to_unit_matrix(const SkPoint pts[2]) { |
43 SkVector vec = pts[1] - pts[0]; | 43 SkVector vec = pts[1] - pts[0]; |
44 SkScalar mag = vec.length(); | 44 SkScalar mag = vec.length(); |
45 SkScalar inv = mag ? SkScalarInvert(mag) : 0; | 45 SkScalar inv = mag ? SkScalarInvert(mag) : 0; |
46 | 46 |
47 vec.scale(inv); | 47 vec.scale(inv); |
48 matrix->setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY); | 48 SkMatrix matrix; |
49 matrix->postTranslate(-pts[0].fX, -pts[0].fY); | 49 matrix.setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY); |
50 matrix->postScale(inv, inv); | 50 matrix.postTranslate(-pts[0].fX, -pts[0].fY); |
| 51 matrix.postScale(inv, inv); |
| 52 return matrix; |
51 } | 53 } |
52 | 54 |
53 /////////////////////////////////////////////////////////////////////////////// | 55 /////////////////////////////////////////////////////////////////////////////// |
54 | 56 |
55 SkLinearGradient::SkLinearGradient(const SkPoint pts[2], const Descriptor& desc) | 57 SkLinearGradient::SkLinearGradient(const SkPoint pts[2], const Descriptor& desc) |
56 : SkGradientShaderBase(desc) | 58 : SkGradientShaderBase(desc, pts_to_unit_matrix(pts)) |
57 , fStart(pts[0]) | 59 , fStart(pts[0]) |
58 , fEnd(pts[1]) | 60 , fEnd(pts[1]) { |
59 { | |
60 pts_to_unit_matrix(pts, &fPtsToUnit); | |
61 } | 61 } |
62 | 62 |
63 SkFlattenable* SkLinearGradient::CreateProc(SkReadBuffer& buffer) { | 63 SkFlattenable* SkLinearGradient::CreateProc(SkReadBuffer& buffer) { |
64 DescriptorScope desc; | 64 DescriptorScope desc; |
65 if (!desc.unflatten(buffer)) { | 65 if (!desc.unflatten(buffer)) { |
66 return NULL; | 66 return NULL; |
67 } | 67 } |
68 SkPoint pts[2]; | 68 SkPoint pts[2]; |
69 pts[0] = buffer.readPoint(); | 69 pts[0] = buffer.readPoint(); |
70 pts[1] = buffer.readPoint(); | 70 pts[1] = buffer.readPoint(); |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 str->append("SkLinearGradient ("); | 599 str->append("SkLinearGradient ("); |
600 | 600 |
601 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); | 601 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); |
602 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); | 602 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); |
603 | 603 |
604 this->INHERITED::toString(str); | 604 this->INHERITED::toString(str); |
605 | 605 |
606 str->append(")"); | 606 str->append(")"); |
607 } | 607 } |
608 #endif | 608 #endif |
OLD | NEW |