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

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: non-const canvas ptr 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
« no previous file with comments | « src/core/SkRecords.h ('k') | src/pipe/SkGPipePriv.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 /* 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 462
463 static SkString sweepCode(const SkShader::GradientInfo& info, 463 static SkString sweepCode(const SkShader::GradientInfo& info,
464 const SkMatrix& perspectiveRemover) { 464 const SkMatrix& perspectiveRemover) {
465 SkString function("{exch atan 360 div\n"); 465 SkString function("{exch atan 360 div\n");
466 tileModeCode(info.fTileMode, &function); 466 tileModeCode(info.fTileMode, &function);
467 gradientFunctionCode(info, &function); 467 gradientFunctionCode(info, &function);
468 function.append("}"); 468 function.append("}");
469 return function; 469 return function;
470 } 470 }
471 471
472 static void drawBitmapMatrix(SkCanvas* canvas, const SkBitmap& bm, const SkMatri x& matrix) {
473 SkAutoCanvasRestore acr(canvas, true);
474 canvas->concat(matrix);
475 canvas->drawBitmap(bm, 0, 0);
476 }
477
472 class SkPDFShader::State { 478 class SkPDFShader::State {
473 public: 479 public:
474 SkShader::GradientType fType; 480 SkShader::GradientType fType;
475 SkShader::GradientInfo fInfo; 481 SkShader::GradientInfo fInfo;
476 SkAutoFree fColorData; // This provides storage for arrays in fInfo. 482 SkAutoFree fColorData; // This provides storage for arrays in fInfo.
477 SkMatrix fCanvasTransform; 483 SkMatrix fCanvasTransform;
478 SkMatrix fShaderTransform; 484 SkMatrix fShaderTransform;
479 SkIRect fBBox; 485 SkIRect fBBox;
480 486
481 SkBitmap fImage; 487 SkBitmap fImage;
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 canvas.drawBitmap(*image, 0, 0); 1014 canvas.drawBitmap(*image, 0, 0);
1009 1015
1010 SkScalar width = SkIntToScalar(image->width()); 1016 SkScalar width = SkIntToScalar(image->width());
1011 SkScalar height = SkIntToScalar(image->height()); 1017 SkScalar height = SkIntToScalar(image->height());
1012 1018
1013 // Tiling is implied. First we handle mirroring. 1019 // Tiling is implied. First we handle mirroring.
1014 if (tileModes[0] == SkShader::kMirror_TileMode) { 1020 if (tileModes[0] == SkShader::kMirror_TileMode) {
1015 SkMatrix xMirror; 1021 SkMatrix xMirror;
1016 xMirror.setScale(-1, 1); 1022 xMirror.setScale(-1, 1);
1017 xMirror.postTranslate(2 * width, 0); 1023 xMirror.postTranslate(2 * width, 0);
1018 canvas.drawBitmapMatrix(*image, xMirror); 1024 drawBitmapMatrix(&canvas, *image, xMirror);
1019 patternBBox.fRight += width; 1025 patternBBox.fRight += width;
1020 } 1026 }
1021 if (tileModes[1] == SkShader::kMirror_TileMode) { 1027 if (tileModes[1] == SkShader::kMirror_TileMode) {
1022 SkMatrix yMirror; 1028 SkMatrix yMirror;
1023 yMirror.setScale(SK_Scalar1, -SK_Scalar1); 1029 yMirror.setScale(SK_Scalar1, -SK_Scalar1);
1024 yMirror.postTranslate(0, 2 * height); 1030 yMirror.postTranslate(0, 2 * height);
1025 canvas.drawBitmapMatrix(*image, yMirror); 1031 drawBitmapMatrix(&canvas, *image, yMirror);
1026 patternBBox.fBottom += height; 1032 patternBBox.fBottom += height;
1027 } 1033 }
1028 if (tileModes[0] == SkShader::kMirror_TileMode && 1034 if (tileModes[0] == SkShader::kMirror_TileMode &&
1029 tileModes[1] == SkShader::kMirror_TileMode) { 1035 tileModes[1] == SkShader::kMirror_TileMode) {
1030 SkMatrix mirror; 1036 SkMatrix mirror;
1031 mirror.setScale(-1, -1); 1037 mirror.setScale(-1, -1);
1032 mirror.postTranslate(2 * width, 2 * height); 1038 mirror.postTranslate(2 * width, 2 * height);
1033 canvas.drawBitmapMatrix(*image, mirror); 1039 drawBitmapMatrix(&canvas, *image, mirror);
1034 } 1040 }
1035 1041
1036 // Then handle Clamping, which requires expanding the pattern canvas to 1042 // Then handle Clamping, which requires expanding the pattern canvas to
1037 // cover the entire surfaceBBox. 1043 // cover the entire surfaceBBox.
1038 1044
1039 // If both x and y are in clamp mode, we start by filling in the corners. 1045 // 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.) 1046 // (Which are just a rectangles of the corner colors.)
1041 if (tileModes[0] == SkShader::kClamp_TileMode && 1047 if (tileModes[0] == SkShader::kClamp_TileMode &&
1042 tileModes[1] == SkShader::kClamp_TileMode) { 1048 tileModes[1] == SkShader::kClamp_TileMode) {
1043 SkPaint paint; 1049 SkPaint paint;
(...skipping 30 matching lines...) Expand all
1074 // Then expand the left, right, top, then bottom. 1080 // Then expand the left, right, top, then bottom.
1075 if (tileModes[0] == SkShader::kClamp_TileMode) { 1081 if (tileModes[0] == SkShader::kClamp_TileMode) {
1076 SkIRect subset = SkIRect::MakeXYWH(0, 0, 1, image->height()); 1082 SkIRect subset = SkIRect::MakeXYWH(0, 0, 1, image->height());
1077 if (deviceBounds.left() < 0) { 1083 if (deviceBounds.left() < 0) {
1078 SkBitmap left; 1084 SkBitmap left;
1079 SkAssertResult(image->extractSubset(&left, subset)); 1085 SkAssertResult(image->extractSubset(&left, subset));
1080 1086
1081 SkMatrix leftMatrix; 1087 SkMatrix leftMatrix;
1082 leftMatrix.setScale(-deviceBounds.left(), 1); 1088 leftMatrix.setScale(-deviceBounds.left(), 1);
1083 leftMatrix.postTranslate(deviceBounds.left(), 0); 1089 leftMatrix.postTranslate(deviceBounds.left(), 0);
1084 canvas.drawBitmapMatrix(left, leftMatrix); 1090 drawBitmapMatrix(&canvas, left, leftMatrix);
1085 1091
1086 if (tileModes[1] == SkShader::kMirror_TileMode) { 1092 if (tileModes[1] == SkShader::kMirror_TileMode) {
1087 leftMatrix.postScale(SK_Scalar1, -SK_Scalar1); 1093 leftMatrix.postScale(SK_Scalar1, -SK_Scalar1);
1088 leftMatrix.postTranslate(0, 2 * height); 1094 leftMatrix.postTranslate(0, 2 * height);
1089 canvas.drawBitmapMatrix(left, leftMatrix); 1095 drawBitmapMatrix(&canvas, left, leftMatrix);
1090 } 1096 }
1091 patternBBox.fLeft = 0; 1097 patternBBox.fLeft = 0;
1092 } 1098 }
1093 1099
1094 if (deviceBounds.right() > width) { 1100 if (deviceBounds.right() > width) {
1095 SkBitmap right; 1101 SkBitmap right;
1096 subset.offset(image->width() - 1, 0); 1102 subset.offset(image->width() - 1, 0);
1097 SkAssertResult(image->extractSubset(&right, subset)); 1103 SkAssertResult(image->extractSubset(&right, subset));
1098 1104
1099 SkMatrix rightMatrix; 1105 SkMatrix rightMatrix;
1100 rightMatrix.setScale(deviceBounds.right() - width, 1); 1106 rightMatrix.setScale(deviceBounds.right() - width, 1);
1101 rightMatrix.postTranslate(width, 0); 1107 rightMatrix.postTranslate(width, 0);
1102 canvas.drawBitmapMatrix(right, rightMatrix); 1108 drawBitmapMatrix(&canvas, right, rightMatrix);
1103 1109
1104 if (tileModes[1] == SkShader::kMirror_TileMode) { 1110 if (tileModes[1] == SkShader::kMirror_TileMode) {
1105 rightMatrix.postScale(SK_Scalar1, -SK_Scalar1); 1111 rightMatrix.postScale(SK_Scalar1, -SK_Scalar1);
1106 rightMatrix.postTranslate(0, 2 * height); 1112 rightMatrix.postTranslate(0, 2 * height);
1107 canvas.drawBitmapMatrix(right, rightMatrix); 1113 drawBitmapMatrix(&canvas, right, rightMatrix);
1108 } 1114 }
1109 patternBBox.fRight = deviceBounds.width(); 1115 patternBBox.fRight = deviceBounds.width();
1110 } 1116 }
1111 } 1117 }
1112 1118
1113 if (tileModes[1] == SkShader::kClamp_TileMode) { 1119 if (tileModes[1] == SkShader::kClamp_TileMode) {
1114 SkIRect subset = SkIRect::MakeXYWH(0, 0, image->width(), 1); 1120 SkIRect subset = SkIRect::MakeXYWH(0, 0, image->width(), 1);
1115 if (deviceBounds.top() < 0) { 1121 if (deviceBounds.top() < 0) {
1116 SkBitmap top; 1122 SkBitmap top;
1117 SkAssertResult(image->extractSubset(&top, subset)); 1123 SkAssertResult(image->extractSubset(&top, subset));
1118 1124
1119 SkMatrix topMatrix; 1125 SkMatrix topMatrix;
1120 topMatrix.setScale(SK_Scalar1, -deviceBounds.top()); 1126 topMatrix.setScale(SK_Scalar1, -deviceBounds.top());
1121 topMatrix.postTranslate(0, deviceBounds.top()); 1127 topMatrix.postTranslate(0, deviceBounds.top());
1122 canvas.drawBitmapMatrix(top, topMatrix); 1128 drawBitmapMatrix(&canvas, top, topMatrix);
1123 1129
1124 if (tileModes[0] == SkShader::kMirror_TileMode) { 1130 if (tileModes[0] == SkShader::kMirror_TileMode) {
1125 topMatrix.postScale(-1, 1); 1131 topMatrix.postScale(-1, 1);
1126 topMatrix.postTranslate(2 * width, 0); 1132 topMatrix.postTranslate(2 * width, 0);
1127 canvas.drawBitmapMatrix(top, topMatrix); 1133 drawBitmapMatrix(&canvas, top, topMatrix);
1128 } 1134 }
1129 patternBBox.fTop = 0; 1135 patternBBox.fTop = 0;
1130 } 1136 }
1131 1137
1132 if (deviceBounds.bottom() > height) { 1138 if (deviceBounds.bottom() > height) {
1133 SkBitmap bottom; 1139 SkBitmap bottom;
1134 subset.offset(0, image->height() - 1); 1140 subset.offset(0, image->height() - 1);
1135 SkAssertResult(image->extractSubset(&bottom, subset)); 1141 SkAssertResult(image->extractSubset(&bottom, subset));
1136 1142
1137 SkMatrix bottomMatrix; 1143 SkMatrix bottomMatrix;
1138 bottomMatrix.setScale(SK_Scalar1, deviceBounds.bottom() - height); 1144 bottomMatrix.setScale(SK_Scalar1, deviceBounds.bottom() - height);
1139 bottomMatrix.postTranslate(0, height); 1145 bottomMatrix.postTranslate(0, height);
1140 canvas.drawBitmapMatrix(bottom, bottomMatrix); 1146 drawBitmapMatrix(&canvas, bottom, bottomMatrix);
1141 1147
1142 if (tileModes[0] == SkShader::kMirror_TileMode) { 1148 if (tileModes[0] == SkShader::kMirror_TileMode) {
1143 bottomMatrix.postScale(-1, 1); 1149 bottomMatrix.postScale(-1, 1);
1144 bottomMatrix.postTranslate(2 * width, 0); 1150 bottomMatrix.postTranslate(2 * width, 0);
1145 canvas.drawBitmapMatrix(bottom, bottomMatrix); 1151 drawBitmapMatrix(&canvas, bottom, bottomMatrix);
1146 } 1152 }
1147 patternBBox.fBottom = deviceBounds.height(); 1153 patternBBox.fBottom = deviceBounds.height();
1148 } 1154 }
1149 } 1155 }
1150 1156
1151 // Put the canvas into the pattern stream (fContent). 1157 // Put the canvas into the pattern stream (fContent).
1152 SkAutoTUnref<SkStream> content(pattern.content()); 1158 SkAutoTUnref<SkStream> content(pattern.content());
1153 setData(content.get()); 1159 setData(content.get());
1154 SkPDFResourceDict* resourceDict = pattern.getResourceDict(); 1160 SkPDFResourceDict* resourceDict = pattern.getResourceDict();
1155 resourceDict->getReferencedResources(fResources, &fResources, false); 1161 resourceDict->getReferencedResources(fResources, &fResources, false);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 return false; 1339 return false;
1334 } 1340 }
1335 1341
1336 void SkPDFShader::State::AllocateGradientInfoStorage() { 1342 void SkPDFShader::State::AllocateGradientInfoStorage() {
1337 fColorData.set(sk_malloc_throw( 1343 fColorData.set(sk_malloc_throw(
1338 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); 1344 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar))));
1339 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); 1345 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get());
1340 fInfo.fColorOffsets = 1346 fInfo.fColorOffsets =
1341 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); 1347 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount);
1342 } 1348 }
OLDNEW
« no previous file with comments | « src/core/SkRecords.h ('k') | src/pipe/SkGPipePriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698