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

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

Issue 1848383002: SkPDF: properly dedup bitmaps in shaders (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-04-01 (Friday) 14:35:15 EDT Created 4 years, 8 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/SkBitmapKey.h ('k') | 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 * 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 class SkPDFShader::State { 423 class SkPDFShader::State {
424 public: 424 public:
425 SkShader::GradientType fType; 425 SkShader::GradientType fType;
426 SkShader::GradientInfo fInfo; 426 SkShader::GradientInfo fInfo;
427 SkAutoFree fColorData; // This provides storage for arrays in fInfo. 427 SkAutoFree fColorData; // This provides storage for arrays in fInfo.
428 SkMatrix fCanvasTransform; 428 SkMatrix fCanvasTransform;
429 SkMatrix fShaderTransform; 429 SkMatrix fShaderTransform;
430 SkIRect fBBox; 430 SkIRect fBBox;
431 431
432 SkBitmap fImage; 432 SkBitmap fImage;
433 uint32_t fPixelGeneration; 433 SkBitmapKey fBitmapKey;
434 SkShader::TileMode fImageTileModes[2]; 434 SkShader::TileMode fImageTileModes[2];
435 435
436 State(SkShader* shader, const SkMatrix& canvasTransform, 436 State(SkShader* shader, const SkMatrix& canvasTransform,
437 const SkIRect& bbox, SkScalar rasterScale); 437 const SkIRect& bbox, SkScalar rasterScale);
438 438
439 bool operator==(const State& b) const; 439 bool operator==(const State& b) const;
440 440
441 SkPDFShader::State* CreateAlphaToLuminosityState() const; 441 SkPDFShader::State* CreateAlphaToLuminosityState() const;
442 SkPDFShader::State* CreateOpaqueState() const; 442 SkPDFShader::State* CreateOpaqueState() const;
443 443
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 1039
1040 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { 1040 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const {
1041 if (fType != b.fType || 1041 if (fType != b.fType ||
1042 fCanvasTransform != b.fCanvasTransform || 1042 fCanvasTransform != b.fCanvasTransform ||
1043 fShaderTransform != b.fShaderTransform || 1043 fShaderTransform != b.fShaderTransform ||
1044 fBBox != b.fBBox) { 1044 fBBox != b.fBBox) {
1045 return false; 1045 return false;
1046 } 1046 }
1047 1047
1048 if (fType == SkShader::kNone_GradientType) { 1048 if (fType == SkShader::kNone_GradientType) {
1049 if (fPixelGeneration != b.fPixelGeneration || 1049 if (fBitmapKey != b.fBitmapKey ||
1050 fPixelGeneration == 0 || 1050 fBitmapKey.id() == 0 ||
1051 fImageTileModes[0] != b.fImageTileModes[0] || 1051 fImageTileModes[0] != b.fImageTileModes[0] ||
1052 fImageTileModes[1] != b.fImageTileModes[1]) { 1052 fImageTileModes[1] != b.fImageTileModes[1]) {
1053 return false; 1053 return false;
1054 } 1054 }
1055 } else { 1055 } else {
1056 if (fInfo.fColorCount != b.fInfo.fColorCount || 1056 if (fInfo.fColorCount != b.fInfo.fColorCount ||
1057 memcmp(fInfo.fColors, b.fInfo.fColors, 1057 memcmp(fInfo.fColors, b.fInfo.fColors,
1058 sizeof(SkColor) * fInfo.fColorCount) != 0 || 1058 sizeof(SkColor) * fInfo.fColorCount) != 0 ||
1059 memcmp(fInfo.fColorOffsets, b.fInfo.fColorOffsets, 1059 memcmp(fInfo.fColorOffsets, b.fInfo.fColorOffsets,
1060 sizeof(SkScalar) * fInfo.fColorCount) != 0 || 1060 sizeof(SkScalar) * fInfo.fColorCount) != 0 ||
(...skipping 25 matching lines...) Expand all
1086 case SkShader::kColor_GradientType: 1086 case SkShader::kColor_GradientType:
1087 break; 1087 break;
1088 } 1088 }
1089 } 1089 }
1090 return true; 1090 return true;
1091 } 1091 }
1092 1092
1093 SkPDFShader::State::State(SkShader* shader, const SkMatrix& canvasTransform, 1093 SkPDFShader::State::State(SkShader* shader, const SkMatrix& canvasTransform,
1094 const SkIRect& bbox, SkScalar rasterScale) 1094 const SkIRect& bbox, SkScalar rasterScale)
1095 : fCanvasTransform(canvasTransform), 1095 : fCanvasTransform(canvasTransform),
1096 fBBox(bbox), 1096 fBBox(bbox) {
1097 fPixelGeneration(0) {
1098 fInfo.fColorCount = 0; 1097 fInfo.fColorCount = 0;
1099 fInfo.fColors = nullptr; 1098 fInfo.fColors = nullptr;
1100 fInfo.fColorOffsets = nullptr; 1099 fInfo.fColorOffsets = nullptr;
1101 fShaderTransform = shader->getLocalMatrix(); 1100 fShaderTransform = shader->getLocalMatrix();
1102 fImageTileModes[0] = fImageTileModes[1] = SkShader::kClamp_TileMode; 1101 fImageTileModes[0] = fImageTileModes[1] = SkShader::kClamp_TileMode;
1103 1102
1104 fType = shader->asAGradient(&fInfo); 1103 fType = shader->asAGradient(&fInfo);
1105 1104
1106 if (fType == SkShader::kNone_GradientType) { 1105 if (fType == SkShader::kNone_GradientType) {
1107 SkMatrix matrix; 1106 SkMatrix matrix;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 p.setShader(sk_ref_sp(shader)); 1140 p.setShader(sk_ref_sp(shader));
1142 1141
1143 SkCanvas canvas(fImage); 1142 SkCanvas canvas(fImage);
1144 canvas.scale(scale.width(), scale.height()); 1143 canvas.scale(scale.width(), scale.height());
1145 canvas.translate(-shaderRect.x(), -shaderRect.y()); 1144 canvas.translate(-shaderRect.x(), -shaderRect.y());
1146 canvas.drawPaint(p); 1145 canvas.drawPaint(p);
1147 1146
1148 fShaderTransform.setTranslate(shaderRect.x(), shaderRect.y()); 1147 fShaderTransform.setTranslate(shaderRect.x(), shaderRect.y());
1149 fShaderTransform.preScale(1 / scale.width(), 1 / scale.height()); 1148 fShaderTransform.preScale(1 / scale.width(), 1 / scale.height());
1150 } 1149 }
1151 fPixelGeneration = fImage.getGenerationID(); 1150 fBitmapKey = SkBitmapKey(fImage);
1152 } else { 1151 } else {
1153 AllocateGradientInfoStorage(); 1152 AllocateGradientInfoStorage();
1154 shader->asAGradient(&fInfo); 1153 shader->asAGradient(&fInfo);
1155 } 1154 }
1156 } 1155 }
1157 1156
1158 SkPDFShader::State::State(const SkPDFShader::State& other) 1157 SkPDFShader::State::State(const SkPDFShader::State& other)
1159 : fType(other.fType), 1158 : fType(other.fType),
1160 fCanvasTransform(other.fCanvasTransform), 1159 fCanvasTransform(other.fCanvasTransform),
1161 fShaderTransform(other.fShaderTransform), 1160 fShaderTransform(other.fShaderTransform),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 return false; 1225 return false;
1227 } 1226 }
1228 1227
1229 void SkPDFShader::State::AllocateGradientInfoStorage() { 1228 void SkPDFShader::State::AllocateGradientInfoStorage() {
1230 fColorData.set(sk_malloc_throw( 1229 fColorData.set(sk_malloc_throw(
1231 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); 1230 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar))));
1232 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); 1231 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get());
1233 fInfo.fColorOffsets = 1232 fInfo.fColorOffsets =
1234 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); 1233 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount);
1235 } 1234 }
OLDNEW
« no previous file with comments | « src/pdf/SkBitmapKey.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698