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

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

Issue 901303003: [PDF] Fix shader fallback mapping when clipped (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: 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 | « no previous file | no next file » | 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 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 if (fType == SkShader::kNone_GradientType) { 1212 if (fType == SkShader::kNone_GradientType) {
1213 SkShader::BitmapType bitmapType; 1213 SkShader::BitmapType bitmapType;
1214 SkMatrix matrix; 1214 SkMatrix matrix;
1215 bitmapType = shader.asABitmap(&fImage, &matrix, fImageTileModes); 1215 bitmapType = shader.asABitmap(&fImage, &matrix, fImageTileModes);
1216 if (bitmapType != SkShader::kDefault_BitmapType) { 1216 if (bitmapType != SkShader::kDefault_BitmapType) {
1217 // Generic fallback for unsupported shaders: 1217 // Generic fallback for unsupported shaders:
1218 // * allocate a bbox-sized bitmap 1218 // * allocate a bbox-sized bitmap
1219 // * shade the whole area 1219 // * shade the whole area
1220 // * use the result as a bitmap shader 1220 // * use the result as a bitmap shader
1221 1221
1222 // bbox is in device space. While that's exactly what we want for si zing our bitmap,
1223 // we need to map it into shader space for adjustments (to match
1224 // SkPDFImageShader::Create's behavior).
1225 SkRect shaderRect = SkRect::Make(bbox);
robertphillips 2015/02/12 21:12:59 inverse_transform_bbox ?
f(malita) 2015/02/12 21:28:33 Done.
1226 if (!inverseTransformBBox(canvasTransform, &shaderRect)) {
1227 fImage.reset();
1228 return;
1229 }
1230
1222 // Clamp the bitmap size to about 1M pixels 1231 // Clamp the bitmap size to about 1M pixels
1223 static const SkScalar kMaxBitmapArea = 1024 * 1024; 1232 static const SkScalar kMaxBitmapArea = 1024 * 1024;
1224 SkScalar bitmapArea = rasterScale * bbox.width() * rasterScale * bbo x.height(); 1233 SkScalar bitmapArea = rasterScale * bbox.width() * rasterScale * bbo x.height();
1225 if (bitmapArea > kMaxBitmapArea) { 1234 if (bitmapArea > kMaxBitmapArea) {
1226 rasterScale *= SkScalarSqrt(SkScalarDiv(kMaxBitmapArea, bitmapAr ea)); 1235 rasterScale *= SkScalarSqrt(SkScalarDiv(kMaxBitmapArea, bitmapAr ea));
1227 } 1236 }
1228 1237
1229 SkISize size = SkISize::Make(SkScalarRoundToInt(rasterScale * bbox.w idth()), 1238 SkISize size = SkISize::Make(SkScalarRoundToInt(rasterScale * bbox.w idth()),
1230 SkScalarRoundToInt(rasterScale * bbox.h eight())); 1239 SkScalarRoundToInt(rasterScale * bbox.h eight()));
1231 SkSize scale = SkSize::Make(SkIntToScalar(size.width()) / SkIntToSca lar(bbox.width()), 1240 SkSize scale = SkSize::Make(SkIntToScalar(size.width()) / shaderRect .width(),
1232 SkIntToScalar(size.height()) / SkIntToSc alar(bbox.height())); 1241 SkIntToScalar(size.height()) / shaderRec t.height());
1233 1242
1234 fImage.allocN32Pixels(size.width(), size.height()); 1243 fImage.allocN32Pixels(size.width(), size.height());
1235 fImage.eraseColor(SK_ColorTRANSPARENT); 1244 fImage.eraseColor(SK_ColorTRANSPARENT);
1236 1245
1237 SkPaint p; 1246 SkPaint p;
1238 p.setShader(const_cast<SkShader*>(&shader)); 1247 p.setShader(const_cast<SkShader*>(&shader));
1239 1248
1240 SkCanvas canvas(fImage); 1249 SkCanvas canvas(fImage);
1241 canvas.scale(scale.width(), scale.height()); 1250 canvas.scale(scale.width(), scale.height());
1242 canvas.translate(-SkIntToScalar(bbox.x()), -SkIntToScalar(bbox.y())) ; 1251 canvas.translate(-shaderRect.x(), -shaderRect.y());
1243 canvas.drawPaint(p); 1252 canvas.drawPaint(p);
1244 1253
1245 fShaderTransform.setTranslate(SkIntToScalar(bbox.x()), SkIntToScalar (bbox.y())); 1254 fShaderTransform.setTranslate(shaderRect.x(), shaderRect.y());
1246 fShaderTransform.preScale(1 / scale.width(), 1 / scale.height()); 1255 fShaderTransform.preScale(1 / scale.width(), 1 / scale.height());
1247 } else { 1256 } else {
1248 SkASSERT(matrix.isIdentity()); 1257 SkASSERT(matrix.isIdentity());
1249 } 1258 }
1250 fPixelGeneration = fImage.getGenerationID(); 1259 fPixelGeneration = fImage.getGenerationID();
1251 } else { 1260 } else {
1252 AllocateGradientInfoStorage(); 1261 AllocateGradientInfoStorage();
1253 shader.asAGradient(&fInfo); 1262 shader.asAGradient(&fInfo);
1254 } 1263 }
1255 } 1264 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 return false; 1334 return false;
1326 } 1335 }
1327 1336
1328 void SkPDFShader::State::AllocateGradientInfoStorage() { 1337 void SkPDFShader::State::AllocateGradientInfoStorage() {
1329 fColorData.set(sk_malloc_throw( 1338 fColorData.set(sk_malloc_throw(
1330 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); 1339 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar))));
1331 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); 1340 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get());
1332 fInfo.fColorOffsets = 1341 fInfo.fColorOffsets =
1333 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); 1342 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount);
1334 } 1343 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698