Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: src/pdf/SkPDFShader.cpp

Issue 2190883003: SkPDF: PDFStream has-a not is-a PDFDict (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-07-29 (Friday) 12:30:20 EDT Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFShader.h ('k') | src/pdf/SkPDFStream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 8
9 #include "SkPDFShader.h" 9 #include "SkPDFShader.h"
10 10
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 SkPDFAlphaFunctionShader* alphaFunctionShader = 736 SkPDFAlphaFunctionShader* alphaFunctionShader =
737 new SkPDFAlphaFunctionShader(autoState->release()); 737 new SkPDFAlphaFunctionShader(autoState->release());
738 738
739 auto resourceDict = 739 auto resourceDict =
740 get_gradient_resource_dict(colorShader.get(), alphaGs.get()); 740 get_gradient_resource_dict(colorShader.get(), alphaGs.get());
741 741
742 std::unique_ptr<SkStreamAsset> colorStream( 742 std::unique_ptr<SkStreamAsset> colorStream(
743 create_pattern_fill_content(0, bbox)); 743 create_pattern_fill_content(0, bbox));
744 alphaFunctionShader->setData(std::move(colorStream)); 744 alphaFunctionShader->setData(std::move(colorStream));
745 745
746 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), 746 populate_tiling_pattern_dict(
747 SkMatrix::I()); 747 alphaFunctionShader->dict(), bbox, resourceDict.get(),
748 SkMatrix::I());
748 doc->canon()->addAlphaShader(alphaFunctionShader); 749 doc->canon()->addAlphaShader(alphaFunctionShader);
749 return alphaFunctionShader; 750 return alphaFunctionShader;
750 } 751 }
751 752
752 // Finds affine and persp such that in = affine * persp. 753 // Finds affine and persp such that in = affine * persp.
753 // but it returns the inverse of perspective matrix. 754 // but it returns the inverse of perspective matrix.
754 static bool split_perspective(const SkMatrix in, SkMatrix* affine, 755 static bool split_perspective(const SkMatrix in, SkMatrix* affine,
755 SkMatrix* perspectiveInverse) { 756 SkMatrix* perspectiveInverse) {
756 const SkScalar p2 = in[SkMatrix::kMPersp2]; 757 const SkScalar p2 = in[SkMatrix::kMPersp2];
757 758
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 range->appendInt(0); 798 range->appendInt(0);
798 range->appendInt(1); 799 range->appendInt(1);
799 return range; 800 return range;
800 } 801 }
801 802
802 static sk_sp<SkPDFStream> make_ps_function( 803 static sk_sp<SkPDFStream> make_ps_function(
803 std::unique_ptr<SkStreamAsset> psCode, 804 std::unique_ptr<SkStreamAsset> psCode,
804 SkPDFArray* domain, 805 SkPDFArray* domain,
805 sk_sp<SkPDFObject> range) { 806 sk_sp<SkPDFObject> range) {
806 auto result = sk_make_sp<SkPDFStream>(std::move(psCode)); 807 auto result = sk_make_sp<SkPDFStream>(std::move(psCode));
807 result->insertInt("FunctionType", 4); 808 result->dict()->insertInt("FunctionType", 4);
808 result->insertObject("Domain", sk_ref_sp(domain)); 809 result->dict()->insertObject("Domain", sk_ref_sp(domain));
809 result->insertObject("Range", std::move(range)); 810 result->dict()->insertObject("Range", std::move(range));
810 return result; 811 return result;
811 } 812 }
812 813
813 // catch cases where the inner just touches the outer circle 814 // catch cases where the inner just touches the outer circle
814 // and make the inner circle just inside the outer one to match raster 815 // and make the inner circle just inside the outer one to match raster
815 static void FixUpRadius(const SkPoint& p1, SkScalar& r1, const SkPoint& p2, SkSc alar& r2) { 816 static void FixUpRadius(const SkPoint& p1, SkScalar& r1, const SkPoint& p2, SkSc alar& r2) {
816 // detect touching circles 817 // detect touching circles
817 SkScalar distance = SkPoint::Distance(p1, p2); 818 SkScalar distance = SkPoint::Distance(p1, p2);
818 SkScalar subtractRadii = fabs(r1 - r2); 819 SkScalar subtractRadii = fabs(r1 - r2);
819 if (fabs(distance - subtractRadii) < 0.002f) { 820 if (fabs(distance - subtractRadii) < 0.002f) {
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 } 1207 }
1207 patternBBox.fBottom = deviceBounds.height(); 1208 patternBBox.fBottom = deviceBounds.height();
1208 } 1209 }
1209 } 1210 }
1210 1211
1211 // Put the canvas into the pattern stream (fContent). 1212 // Put the canvas into the pattern stream (fContent).
1212 SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->release()); 1213 SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->release());
1213 imageShader->setData(patternDevice->content()); 1214 imageShader->setData(patternDevice->content());
1214 1215
1215 auto resourceDict = patternDevice->makeResourceDict(); 1216 auto resourceDict = patternDevice->makeResourceDict();
1216 populate_tiling_pattern_dict(imageShader, patternBBox, 1217 populate_tiling_pattern_dict(imageShader->dict(), patternBBox,
1217 resourceDict.get(), finalMatrix); 1218 resourceDict.get(), finalMatrix);
1218 1219
1219 imageShader->fShaderState->fImage.unlockPixels(); 1220 imageShader->fShaderState->fImage.unlockPixels();
1220 1221
1221 doc->canon()->addImageShader(imageShader); 1222 doc->canon()->addImageShader(imageShader);
1222 return imageShader; 1223 return imageShader;
1223 } 1224 }
1224 1225
1225 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { 1226 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const {
1226 if (fType != b.fType || 1227 if (fType != b.fType ||
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 return false; 1411 return false;
1411 } 1412 }
1412 1413
1413 void SkPDFShader::State::AllocateGradientInfoStorage() { 1414 void SkPDFShader::State::AllocateGradientInfoStorage() {
1414 fColorData.set(sk_malloc_throw( 1415 fColorData.set(sk_malloc_throw(
1415 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); 1416 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar))));
1416 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); 1417 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get());
1417 fInfo.fColorOffsets = 1418 fInfo.fColorOffsets =
1418 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); 1419 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount);
1419 } 1420 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFShader.h ('k') | src/pdf/SkPDFStream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698