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

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

Issue 941023005: PDF : New factory function for SkPDFDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase on 07d5947 Created 5 years, 10 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/SkPDFDevice.cpp ('k') | tests/AnnotationTest.cpp » ('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 /* 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 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 // For clamp modes, we're only interested in the clip region, whether 935 // For clamp modes, we're only interested in the clip region, whether
936 // or not the main bitmap is in it. 936 // or not the main bitmap is in it.
937 SkShader::TileMode tileModes[2]; 937 SkShader::TileMode tileModes[2];
938 tileModes[0] = state.fImageTileModes[0]; 938 tileModes[0] = state.fImageTileModes[0];
939 tileModes[1] = state.fImageTileModes[1]; 939 tileModes[1] = state.fImageTileModes[1];
940 if (tileModes[0] != SkShader::kClamp_TileMode || 940 if (tileModes[0] != SkShader::kClamp_TileMode ||
941 tileModes[1] != SkShader::kClamp_TileMode) { 941 tileModes[1] != SkShader::kClamp_TileMode) {
942 deviceBounds.join(bitmapBounds); 942 deviceBounds.join(bitmapBounds);
943 } 943 }
944 944
945 SkMatrix unflip;
946 unflip.setTranslate(0, SkScalarRoundToScalar(deviceBounds.height()));
947 unflip.preScale(SK_Scalar1, -SK_Scalar1);
948 SkISize size = SkISize::Make(SkScalarRoundToInt(deviceBounds.width()), 945 SkISize size = SkISize::Make(SkScalarRoundToInt(deviceBounds.width()),
949 SkScalarRoundToInt(deviceBounds.height())); 946 SkScalarRoundToInt(deviceBounds.height()));
950 // TODO(edisonn): should we pass here the DCT encoder of the destination dev ice? 947 SkAutoTUnref<SkPDFDevice> patternDevice(
951 // TODO(edisonn): NYI Perspective, use SkPDFDeviceFlattener. 948 SkPDFDevice::CreateUnflipped(size, 72.0f, NULL));
952 SkPDFDevice pattern(size, size, unflip); 949 SkCanvas canvas(patternDevice.get());
953 SkCanvas canvas(&pattern);
954 950
955 SkRect patternBBox; 951 SkRect patternBBox;
956 image->getBounds(&patternBBox); 952 image->getBounds(&patternBBox);
957 953
958 // Translate the canvas so that the bitmap origin is at (0, 0). 954 // Translate the canvas so that the bitmap origin is at (0, 0).
959 canvas.translate(-deviceBounds.left(), -deviceBounds.top()); 955 canvas.translate(-deviceBounds.left(), -deviceBounds.top());
960 patternBBox.offset(-deviceBounds.left(), -deviceBounds.top()); 956 patternBBox.offset(-deviceBounds.left(), -deviceBounds.top());
961 // Undo the translation in the final matrix 957 // Undo the translation in the final matrix
962 finalMatrix.preTranslate(deviceBounds.left(), deviceBounds.top()); 958 finalMatrix.preTranslate(deviceBounds.left(), deviceBounds.top());
963 959
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 if (tileModes[0] == SkShader::kMirror_TileMode) { 1097 if (tileModes[0] == SkShader::kMirror_TileMode) {
1102 bottomMatrix.postScale(-1, 1); 1098 bottomMatrix.postScale(-1, 1);
1103 bottomMatrix.postTranslate(2 * width, 0); 1099 bottomMatrix.postTranslate(2 * width, 0);
1104 drawBitmapMatrix(&canvas, bottom, bottomMatrix); 1100 drawBitmapMatrix(&canvas, bottom, bottomMatrix);
1105 } 1101 }
1106 patternBBox.fBottom = deviceBounds.height(); 1102 patternBBox.fBottom = deviceBounds.height();
1107 } 1103 }
1108 } 1104 }
1109 1105
1110 // Put the canvas into the pattern stream (fContent). 1106 // Put the canvas into the pattern stream (fContent).
1111 SkAutoTDelete<SkStream> content(pattern.content()); 1107 SkAutoTDelete<SkStream> content(patternDevice->content());
1112 1108
1113 SkPDFImageShader* imageShader = 1109 SkPDFImageShader* imageShader =
1114 SkNEW_ARGS(SkPDFImageShader, (autoState->detach())); 1110 SkNEW_ARGS(SkPDFImageShader, (autoState->detach()));
1115 imageShader->setData(content.get()); 1111 imageShader->setData(content.get());
1116 1112
1117 populate_tiling_pattern_dict(imageShader, patternBBox, 1113 populate_tiling_pattern_dict(imageShader,
1118 pattern.getResourceDict(), finalMatrix); 1114 patternBBox,
1115 patternDevice->getResourceDict(),
1116 finalMatrix);
1119 1117
1120 imageShader->fShaderState->fImage.unlockPixels(); 1118 imageShader->fShaderState->fImage.unlockPixels();
1121 1119
1122 SkPDFCanon::GetCanon().addImageShader(imageShader); 1120 SkPDFCanon::GetCanon().addImageShader(imageShader);
1123 return imageShader; 1121 return imageShader;
1124 } 1122 }
1125 1123
1126 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { 1124 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const {
1127 if (fType != b.fType || 1125 if (fType != b.fType ||
1128 fCanvasTransform != b.fCanvasTransform || 1126 fCanvasTransform != b.fCanvasTransform ||
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 return false; 1313 return false;
1316 } 1314 }
1317 1315
1318 void SkPDFShader::State::AllocateGradientInfoStorage() { 1316 void SkPDFShader::State::AllocateGradientInfoStorage() {
1319 fColorData.set(sk_malloc_throw( 1317 fColorData.set(sk_malloc_throw(
1320 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); 1318 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar))));
1321 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); 1319 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get());
1322 fInfo.fColorOffsets = 1320 fInfo.fColorOffsets =
1323 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); 1321 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount);
1324 } 1322 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | tests/AnnotationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698