OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkPDFShader.h" | 10 #include "SkPDFShader.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 return true; | 30 return true; |
31 } | 31 } |
32 | 32 |
33 static void unitToPointsMatrix(const SkPoint pts[2], SkMatrix* matrix) { | 33 static void unitToPointsMatrix(const SkPoint pts[2], SkMatrix* matrix) { |
34 SkVector vec = pts[1] - pts[0]; | 34 SkVector vec = pts[1] - pts[0]; |
35 SkScalar mag = vec.length(); | 35 SkScalar mag = vec.length(); |
36 SkScalar inv = mag ? SkScalarInvert(mag) : 0; | 36 SkScalar inv = mag ? SkScalarInvert(mag) : 0; |
37 | 37 |
38 vec.scale(inv); | 38 vec.scale(inv); |
39 matrix->setSinCos(vec.fY, vec.fX); | 39 matrix->setSinCos(vec.fY, vec.fX); |
40 matrix->preTranslate(pts[0].fX, pts[0].fY); | |
41 matrix->preScale(mag, mag); | 40 matrix->preScale(mag, mag); |
| 41 matrix->postTranslate(pts[0].fX, pts[0].fY); |
42 } | 42 } |
43 | 43 |
44 /* Assumes t + startOffset is on the stack and does a linear interpolation on t | 44 /* Assumes t + startOffset is on the stack and does a linear interpolation on t |
45 between startOffset and endOffset from prevColor to curColor (for each color | 45 between startOffset and endOffset from prevColor to curColor (for each color |
46 component), leaving the result in component order on the stack. It assumes | 46 component), leaving the result in component order on the stack. It assumes |
47 there are always 3 components per color. | 47 there are always 3 components per color. |
48 @param range endOffset - startOffset | 48 @param range endOffset - startOffset |
49 @param curColor[components] The current color components. | 49 @param curColor[components] The current color components. |
50 @param prevColor[components] The previous color components. | 50 @param prevColor[components] The previous color components. |
51 @param result The result ps function. | 51 @param result The result ps function. |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 return; | 602 return; |
603 } | 603 } |
604 | 604 |
605 // Move any scaling (assuming a unit gradient) or translation | 605 // Move any scaling (assuming a unit gradient) or translation |
606 // (and rotation for linear gradient), of the final gradient from | 606 // (and rotation for linear gradient), of the final gradient from |
607 // info->fPoints to the matrix (updating bbox appropriately). Now | 607 // info->fPoints to the matrix (updating bbox appropriately). Now |
608 // the gradient can be drawn on on the unit segment. | 608 // the gradient can be drawn on on the unit segment. |
609 SkMatrix mapperMatrix; | 609 SkMatrix mapperMatrix; |
610 unitToPointsMatrix(transformPoints, &mapperMatrix); | 610 unitToPointsMatrix(transformPoints, &mapperMatrix); |
611 SkMatrix finalMatrix = fState.get()->fCanvasTransform; | 611 SkMatrix finalMatrix = fState.get()->fCanvasTransform; |
| 612 finalMatrix.preConcat(fState.get()->fShaderTransform); |
612 finalMatrix.preConcat(mapperMatrix); | 613 finalMatrix.preConcat(mapperMatrix); |
613 finalMatrix.preConcat(fState.get()->fShaderTransform); | 614 |
614 SkRect bbox; | 615 SkRect bbox; |
615 bbox.set(fState.get()->fBBox); | 616 bbox.set(fState.get()->fBBox); |
616 if (!transformBBox(finalMatrix, &bbox)) { | 617 if (!transformBBox(finalMatrix, &bbox)) { |
617 return; | 618 return; |
618 } | 619 } |
619 | 620 |
620 SkAutoTUnref<SkPDFArray> domain(new SkPDFArray); | 621 SkAutoTUnref<SkPDFArray> domain(new SkPDFArray); |
621 domain->reserve(4); | 622 domain->reserve(4); |
622 domain->appendScalar(bbox.fLeft); | 623 domain->appendScalar(bbox.fLeft); |
623 domain->appendScalar(bbox.fRight); | 624 domain->appendScalar(bbox.fRight); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 fPixelGeneration = fImage.getGenerationID(); | 955 fPixelGeneration = fImage.getGenerationID(); |
955 } else { | 956 } else { |
956 fColorData.set(sk_malloc_throw( | 957 fColorData.set(sk_malloc_throw( |
957 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 958 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
958 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 959 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
959 fInfo.fColorOffsets = | 960 fInfo.fColorOffsets = |
960 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 961 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
961 shader.asAGradient(&fInfo); | 962 shader.asAGradient(&fInfo); |
962 } | 963 } |
963 } | 964 } |
OLD | NEW |