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

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

Issue 789033002: Remove SkCanvas::drawBitmapMatrix() (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 6 years 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
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 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 canvas.drawBitmap(*image, 0, 0); 1008 canvas.drawBitmap(*image, 0, 0);
1009 1009
1010 SkScalar width = SkIntToScalar(image->width()); 1010 SkScalar width = SkIntToScalar(image->width());
1011 SkScalar height = SkIntToScalar(image->height()); 1011 SkScalar height = SkIntToScalar(image->height());
1012 1012
1013 // Tiling is implied. First we handle mirroring. 1013 // Tiling is implied. First we handle mirroring.
1014 if (tileModes[0] == SkShader::kMirror_TileMode) { 1014 if (tileModes[0] == SkShader::kMirror_TileMode) {
1015 SkMatrix xMirror; 1015 SkMatrix xMirror;
1016 xMirror.setScale(-1, 1); 1016 xMirror.setScale(-1, 1);
1017 xMirror.postTranslate(2 * width, 0); 1017 xMirror.postTranslate(2 * width, 0);
1018 canvas.drawBitmapMatrix(*image, xMirror); 1018
mtklein 2014/12/10 14:48:09 Seems like this file uses drawBitmapMatrix often e
f(malita) 2014/12/10 15:33:56 Done.
1019 SkAutoCanvasRestore acr(&canvas, true);
1020 canvas.concat(xMirror);
1021 canvas.drawBitmap(*image, 0, 0);
1022
1019 patternBBox.fRight += width; 1023 patternBBox.fRight += width;
1020 } 1024 }
1021 if (tileModes[1] == SkShader::kMirror_TileMode) { 1025 if (tileModes[1] == SkShader::kMirror_TileMode) {
1022 SkMatrix yMirror; 1026 SkMatrix yMirror;
1023 yMirror.setScale(SK_Scalar1, -SK_Scalar1); 1027 yMirror.setScale(SK_Scalar1, -SK_Scalar1);
1024 yMirror.postTranslate(0, 2 * height); 1028 yMirror.postTranslate(0, 2 * height);
1025 canvas.drawBitmapMatrix(*image, yMirror); 1029
1030 SkAutoCanvasRestore acr(&canvas, true);
1031 canvas.concat(yMirror);
1032 canvas.drawBitmap(*image, 0, 0);
1033
1026 patternBBox.fBottom += height; 1034 patternBBox.fBottom += height;
1027 } 1035 }
1028 if (tileModes[0] == SkShader::kMirror_TileMode && 1036 if (tileModes[0] == SkShader::kMirror_TileMode &&
1029 tileModes[1] == SkShader::kMirror_TileMode) { 1037 tileModes[1] == SkShader::kMirror_TileMode) {
1030 SkMatrix mirror; 1038 SkMatrix mirror;
1031 mirror.setScale(-1, -1); 1039 mirror.setScale(-1, -1);
1032 mirror.postTranslate(2 * width, 2 * height); 1040 mirror.postTranslate(2 * width, 2 * height);
1033 canvas.drawBitmapMatrix(*image, mirror); 1041
1042 SkAutoCanvasRestore acr(&canvas, true);
1043 canvas.concat(mirror);
1044 canvas.drawBitmap(*image, 0, 0);
1034 } 1045 }
1035 1046
1036 // Then handle Clamping, which requires expanding the pattern canvas to 1047 // Then handle Clamping, which requires expanding the pattern canvas to
1037 // cover the entire surfaceBBox. 1048 // cover the entire surfaceBBox.
1038 1049
1039 // If both x and y are in clamp mode, we start by filling in the corners. 1050 // If both x and y are in clamp mode, we start by filling in the corners.
1040 // (Which are just a rectangles of the corner colors.) 1051 // (Which are just a rectangles of the corner colors.)
1041 if (tileModes[0] == SkShader::kClamp_TileMode && 1052 if (tileModes[0] == SkShader::kClamp_TileMode &&
1042 tileModes[1] == SkShader::kClamp_TileMode) { 1053 tileModes[1] == SkShader::kClamp_TileMode) {
1043 SkPaint paint; 1054 SkPaint paint;
(...skipping 30 matching lines...) Expand all
1074 // Then expand the left, right, top, then bottom. 1085 // Then expand the left, right, top, then bottom.
1075 if (tileModes[0] == SkShader::kClamp_TileMode) { 1086 if (tileModes[0] == SkShader::kClamp_TileMode) {
1076 SkIRect subset = SkIRect::MakeXYWH(0, 0, 1, image->height()); 1087 SkIRect subset = SkIRect::MakeXYWH(0, 0, 1, image->height());
1077 if (deviceBounds.left() < 0) { 1088 if (deviceBounds.left() < 0) {
1078 SkBitmap left; 1089 SkBitmap left;
1079 SkAssertResult(image->extractSubset(&left, subset)); 1090 SkAssertResult(image->extractSubset(&left, subset));
1080 1091
1081 SkMatrix leftMatrix; 1092 SkMatrix leftMatrix;
1082 leftMatrix.setScale(-deviceBounds.left(), 1); 1093 leftMatrix.setScale(-deviceBounds.left(), 1);
1083 leftMatrix.postTranslate(deviceBounds.left(), 0); 1094 leftMatrix.postTranslate(deviceBounds.left(), 0);
1084 canvas.drawBitmapMatrix(left, leftMatrix); 1095
1096 {
1097 SkAutoCanvasRestore acr(&canvas, true);
1098 canvas.concat(leftMatrix);
1099 canvas.drawBitmap(left, 0, 0);
1100 }
1085 1101
1086 if (tileModes[1] == SkShader::kMirror_TileMode) { 1102 if (tileModes[1] == SkShader::kMirror_TileMode) {
1087 leftMatrix.postScale(SK_Scalar1, -SK_Scalar1); 1103 leftMatrix.postScale(SK_Scalar1, -SK_Scalar1);
1088 leftMatrix.postTranslate(0, 2 * height); 1104 leftMatrix.postTranslate(0, 2 * height);
1089 canvas.drawBitmapMatrix(left, leftMatrix); 1105
1106 SkAutoCanvasRestore acr(&canvas, true);
1107 canvas.concat(leftMatrix);
1108 canvas.drawBitmap(left, 0, 0);
1090 } 1109 }
1091 patternBBox.fLeft = 0; 1110 patternBBox.fLeft = 0;
1092 } 1111 }
1093 1112
1094 if (deviceBounds.right() > width) { 1113 if (deviceBounds.right() > width) {
1095 SkBitmap right; 1114 SkBitmap right;
1096 subset.offset(image->width() - 1, 0); 1115 subset.offset(image->width() - 1, 0);
1097 SkAssertResult(image->extractSubset(&right, subset)); 1116 SkAssertResult(image->extractSubset(&right, subset));
1098 1117
1099 SkMatrix rightMatrix; 1118 SkMatrix rightMatrix;
1100 rightMatrix.setScale(deviceBounds.right() - width, 1); 1119 rightMatrix.setScale(deviceBounds.right() - width, 1);
1101 rightMatrix.postTranslate(width, 0); 1120 rightMatrix.postTranslate(width, 0);
1102 canvas.drawBitmapMatrix(right, rightMatrix); 1121
1122 {
1123 SkAutoCanvasRestore acr(&canvas, true);
1124 canvas.concat(rightMatrix);
1125 canvas.drawBitmap(right, 0, 0);
1126 }
1103 1127
1104 if (tileModes[1] == SkShader::kMirror_TileMode) { 1128 if (tileModes[1] == SkShader::kMirror_TileMode) {
1105 rightMatrix.postScale(SK_Scalar1, -SK_Scalar1); 1129 rightMatrix.postScale(SK_Scalar1, -SK_Scalar1);
1106 rightMatrix.postTranslate(0, 2 * height); 1130 rightMatrix.postTranslate(0, 2 * height);
1107 canvas.drawBitmapMatrix(right, rightMatrix); 1131
1132 SkAutoCanvasRestore acr(&canvas, true);
1133 canvas.concat(rightMatrix);
1134 canvas.drawBitmap(right, 0, 0);
1108 } 1135 }
1109 patternBBox.fRight = deviceBounds.width(); 1136 patternBBox.fRight = deviceBounds.width();
1110 } 1137 }
1111 } 1138 }
1112 1139
1113 if (tileModes[1] == SkShader::kClamp_TileMode) { 1140 if (tileModes[1] == SkShader::kClamp_TileMode) {
1114 SkIRect subset = SkIRect::MakeXYWH(0, 0, image->width(), 1); 1141 SkIRect subset = SkIRect::MakeXYWH(0, 0, image->width(), 1);
1115 if (deviceBounds.top() < 0) { 1142 if (deviceBounds.top() < 0) {
1116 SkBitmap top; 1143 SkBitmap top;
1117 SkAssertResult(image->extractSubset(&top, subset)); 1144 SkAssertResult(image->extractSubset(&top, subset));
1118 1145
1119 SkMatrix topMatrix; 1146 SkMatrix topMatrix;
1120 topMatrix.setScale(SK_Scalar1, -deviceBounds.top()); 1147 topMatrix.setScale(SK_Scalar1, -deviceBounds.top());
1121 topMatrix.postTranslate(0, deviceBounds.top()); 1148 topMatrix.postTranslate(0, deviceBounds.top());
1122 canvas.drawBitmapMatrix(top, topMatrix); 1149
1150 {
1151 SkAutoCanvasRestore acr(&canvas, true);
1152 canvas.concat(topMatrix);
1153 canvas.drawBitmap(top, 0, 0);
1154 }
1123 1155
1124 if (tileModes[0] == SkShader::kMirror_TileMode) { 1156 if (tileModes[0] == SkShader::kMirror_TileMode) {
1125 topMatrix.postScale(-1, 1); 1157 topMatrix.postScale(-1, 1);
1126 topMatrix.postTranslate(2 * width, 0); 1158 topMatrix.postTranslate(2 * width, 0);
1127 canvas.drawBitmapMatrix(top, topMatrix); 1159
1160 SkAutoCanvasRestore acr(&canvas, true);
1161 canvas.concat(topMatrix);
1162 canvas.drawBitmap(top, 0, 0);
1128 } 1163 }
1129 patternBBox.fTop = 0; 1164 patternBBox.fTop = 0;
1130 } 1165 }
1131 1166
1132 if (deviceBounds.bottom() > height) { 1167 if (deviceBounds.bottom() > height) {
1133 SkBitmap bottom; 1168 SkBitmap bottom;
1134 subset.offset(0, image->height() - 1); 1169 subset.offset(0, image->height() - 1);
1135 SkAssertResult(image->extractSubset(&bottom, subset)); 1170 SkAssertResult(image->extractSubset(&bottom, subset));
1136 1171
1137 SkMatrix bottomMatrix; 1172 SkMatrix bottomMatrix;
1138 bottomMatrix.setScale(SK_Scalar1, deviceBounds.bottom() - height); 1173 bottomMatrix.setScale(SK_Scalar1, deviceBounds.bottom() - height);
1139 bottomMatrix.postTranslate(0, height); 1174 bottomMatrix.postTranslate(0, height);
1140 canvas.drawBitmapMatrix(bottom, bottomMatrix); 1175
1176 {
1177 SkAutoCanvasRestore acr(&canvas, true);
1178 canvas.concat(bottomMatrix);
1179 canvas.drawBitmap(bottom, 0, 0);
1180 }
1141 1181
1142 if (tileModes[0] == SkShader::kMirror_TileMode) { 1182 if (tileModes[0] == SkShader::kMirror_TileMode) {
1143 bottomMatrix.postScale(-1, 1); 1183 bottomMatrix.postScale(-1, 1);
1144 bottomMatrix.postTranslate(2 * width, 0); 1184 bottomMatrix.postTranslate(2 * width, 0);
1145 canvas.drawBitmapMatrix(bottom, bottomMatrix); 1185
1186 SkAutoCanvasRestore acr(&canvas, true);
1187 canvas.concat(bottomMatrix);
1188 canvas.drawBitmap(bottom, 0, 0);
1146 } 1189 }
1147 patternBBox.fBottom = deviceBounds.height(); 1190 patternBBox.fBottom = deviceBounds.height();
1148 } 1191 }
1149 } 1192 }
1150 1193
1151 // Put the canvas into the pattern stream (fContent). 1194 // Put the canvas into the pattern stream (fContent).
1152 SkAutoTUnref<SkStream> content(pattern.content()); 1195 SkAutoTUnref<SkStream> content(pattern.content());
1153 setData(content.get()); 1196 setData(content.get());
1154 SkPDFResourceDict* resourceDict = pattern.getResourceDict(); 1197 SkPDFResourceDict* resourceDict = pattern.getResourceDict();
1155 resourceDict->getReferencedResources(fResources, &fResources, false); 1198 resourceDict->getReferencedResources(fResources, &fResources, false);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 return false; 1376 return false;
1334 } 1377 }
1335 1378
1336 void SkPDFShader::State::AllocateGradientInfoStorage() { 1379 void SkPDFShader::State::AllocateGradientInfoStorage() {
1337 fColorData.set(sk_malloc_throw( 1380 fColorData.set(sk_malloc_throw(
1338 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); 1381 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar))));
1339 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); 1382 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get());
1340 fInfo.fColorOffsets = 1383 fInfo.fColorOffsets =
1341 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); 1384 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount);
1342 } 1385 }
OLDNEW
« src/core/SkPictureFlat.h ('K') | « src/core/SkRecords.h ('k') | src/pipe/SkGPipePriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698