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

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

Issue 2188623004: SkPDF: SkPDFStream takes a unique_ptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/SkPDFFormXObject.cpp ('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 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 state.CreateAlphaToLuminosityState()); 697 state.CreateAlphaToLuminosityState());
698 sk_sp<SkPDFObject> luminosityShader( 698 sk_sp<SkPDFObject> luminosityShader(
699 get_pdf_shader_by_state(doc, dpi, &alphaToLuminosityState)); 699 get_pdf_shader_by_state(doc, dpi, &alphaToLuminosityState));
700 700
701 std::unique_ptr<SkStreamAsset> alphaStream(create_pattern_fill_content(-1, b box)); 701 std::unique_ptr<SkStreamAsset> alphaStream(create_pattern_fill_content(-1, b box));
702 702
703 auto resources = 703 auto resources =
704 get_gradient_resource_dict(luminosityShader.get(), nullptr); 704 get_gradient_resource_dict(luminosityShader.get(), nullptr);
705 705
706 sk_sp<SkPDFFormXObject> alphaMask( 706 sk_sp<SkPDFFormXObject> alphaMask(
707 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); 707 new SkPDFFormXObject(std::move(alphaStream), bbox, resources.get())) ;
708 708
709 return SkPDFGraphicState::GetSMaskGraphicState( 709 return SkPDFGraphicState::GetSMaskGraphicState(
710 alphaMask.get(), false, 710 alphaMask.get(), false,
711 SkPDFGraphicState::kLuminosity_SMaskMode, doc->canon()); 711 SkPDFGraphicState::kLuminosity_SMaskMode, doc->canon());
712 } 712 }
713 713
714 SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create( 714 SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create(
715 SkPDFDocument* doc, 715 SkPDFDocument* doc,
716 SkScalar dpi, 716 SkScalar dpi,
717 std::unique_ptr<SkPDFShader::State>* autoState) { 717 std::unique_ptr<SkPDFShader::State>* autoState) {
(...skipping 14 matching lines...) Expand all
732 auto alphaGs = create_smask_graphic_state(doc, dpi, state); 732 auto alphaGs = create_smask_graphic_state(doc, dpi, state);
733 733
734 SkPDFAlphaFunctionShader* alphaFunctionShader = 734 SkPDFAlphaFunctionShader* alphaFunctionShader =
735 new SkPDFAlphaFunctionShader(autoState->release()); 735 new SkPDFAlphaFunctionShader(autoState->release());
736 736
737 auto resourceDict = 737 auto resourceDict =
738 get_gradient_resource_dict(colorShader.get(), alphaGs.get()); 738 get_gradient_resource_dict(colorShader.get(), alphaGs.get());
739 739
740 std::unique_ptr<SkStreamAsset> colorStream( 740 std::unique_ptr<SkStreamAsset> colorStream(
741 create_pattern_fill_content(0, bbox)); 741 create_pattern_fill_content(0, bbox));
742 alphaFunctionShader->setData(colorStream.get()); 742 alphaFunctionShader->setData(std::move(colorStream));
743 743
744 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), 744 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(),
745 SkMatrix::I()); 745 SkMatrix::I());
746 doc->canon()->addAlphaShader(alphaFunctionShader); 746 doc->canon()->addAlphaShader(alphaFunctionShader);
747 return alphaFunctionShader; 747 return alphaFunctionShader;
748 } 748 }
749 749
750 // Finds affine and persp such that in = affine * persp. 750 // Finds affine and persp such that in = affine * persp.
751 // but it returns the inverse of perspective matrix. 751 // but it returns the inverse of perspective matrix.
752 static bool split_perspective(const SkMatrix in, SkMatrix* affine, 752 static bool split_perspective(const SkMatrix in, SkMatrix* affine,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 range->appendInt(1); 794 range->appendInt(1);
795 range->appendInt(0); 795 range->appendInt(0);
796 range->appendInt(1); 796 range->appendInt(1);
797 return range; 797 return range;
798 } 798 }
799 799
800 static sk_sp<SkPDFStream> make_ps_function( 800 static sk_sp<SkPDFStream> make_ps_function(
801 std::unique_ptr<SkStreamAsset> psCode, 801 std::unique_ptr<SkStreamAsset> psCode,
802 SkPDFArray* domain, 802 SkPDFArray* domain,
803 sk_sp<SkPDFObject> range) { 803 sk_sp<SkPDFObject> range) {
804 auto result = sk_make_sp<SkPDFStream>(psCode.get()); 804 auto result = sk_make_sp<SkPDFStream>(std::move(psCode));
805 result->insertInt("FunctionType", 4); 805 result->insertInt("FunctionType", 4);
806 result->insertObject("Domain", sk_ref_sp(domain)); 806 result->insertObject("Domain", sk_ref_sp(domain));
807 result->insertObject("Range", std::move(range)); 807 result->insertObject("Range", std::move(range));
808 return result; 808 return result;
809 } 809 }
810 810
811 // catch cases where the inner just touches the outer circle 811 // catch cases where the inner just touches the outer circle
812 // and make the inner circle just inside the outer one to match raster 812 // and make the inner circle just inside the outer one to match raster
813 static void FixUpRadius(const SkPoint& p1, SkScalar& r1, const SkPoint& p2, SkSc alar& r2) { 813 static void FixUpRadius(const SkPoint& p1, SkScalar& r1, const SkPoint& p2, SkSc alar& r2) {
814 // detect touching circles 814 // detect touching circles
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 if (tileModes[0] == SkShader::kMirror_TileMode) { 1200 if (tileModes[0] == SkShader::kMirror_TileMode) {
1201 bottomMatrix.postScale(-1, 1); 1201 bottomMatrix.postScale(-1, 1);
1202 bottomMatrix.postTranslate(2 * width, 0); 1202 bottomMatrix.postTranslate(2 * width, 0);
1203 drawBitmapMatrix(&canvas, bottom, bottomMatrix); 1203 drawBitmapMatrix(&canvas, bottom, bottomMatrix);
1204 } 1204 }
1205 patternBBox.fBottom = deviceBounds.height(); 1205 patternBBox.fBottom = deviceBounds.height();
1206 } 1206 }
1207 } 1207 }
1208 1208
1209 // Put the canvas into the pattern stream (fContent). 1209 // Put the canvas into the pattern stream (fContent).
1210 auto content = patternDevice->content();
1211
1212 SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->release()); 1210 SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->release());
1213 imageShader->setData(content.get()); 1211 imageShader->setData(patternDevice->content());
1214 1212
1215 auto resourceDict = patternDevice->makeResourceDict(); 1213 auto resourceDict = patternDevice->makeResourceDict();
1216 populate_tiling_pattern_dict(imageShader, patternBBox, 1214 populate_tiling_pattern_dict(imageShader, patternBBox,
1217 resourceDict.get(), finalMatrix); 1215 resourceDict.get(), finalMatrix);
1218 1216
1219 imageShader->fShaderState->fImage.unlockPixels(); 1217 imageShader->fShaderState->fImage.unlockPixels();
1220 1218
1221 doc->canon()->addImageShader(imageShader); 1219 doc->canon()->addImageShader(imageShader);
1222 return imageShader; 1220 return imageShader;
1223 } 1221 }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 return false; 1408 return false;
1411 } 1409 }
1412 1410
1413 void SkPDFShader::State::AllocateGradientInfoStorage() { 1411 void SkPDFShader::State::AllocateGradientInfoStorage() {
1414 fColorData.set(sk_malloc_throw( 1412 fColorData.set(sk_malloc_throw(
1415 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); 1413 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar))));
1416 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); 1414 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get());
1417 fInfo.fColorOffsets = 1415 fInfo.fColorOffsets =
1418 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); 1416 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount);
1419 } 1417 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFFormXObject.cpp ('k') | src/pdf/SkPDFStream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698