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

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

Issue 1829303002: move setshader to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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
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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 SkShader::GradientInfo fInfo; 427 SkShader::GradientInfo fInfo;
428 SkAutoFree fColorData; // This provides storage for arrays in fInfo. 428 SkAutoFree fColorData; // This provides storage for arrays in fInfo.
429 SkMatrix fCanvasTransform; 429 SkMatrix fCanvasTransform;
430 SkMatrix fShaderTransform; 430 SkMatrix fShaderTransform;
431 SkIRect fBBox; 431 SkIRect fBBox;
432 432
433 SkBitmap fImage; 433 SkBitmap fImage;
434 uint32_t fPixelGeneration; 434 uint32_t fPixelGeneration;
435 SkShader::TileMode fImageTileModes[2]; 435 SkShader::TileMode fImageTileModes[2];
436 436
437 State(const SkShader& shader, const SkMatrix& canvasTransform, 437 State(SkShader* shader, const SkMatrix& canvasTransform,
tomhudson 2016/03/25 14:28:07 Changing PDF to raw pointers instead of sk_sp<>?
reed1 2016/03/25 15:04:31 There are lots of changes we could do internally t
tomhudson 2016/03/25 15:39:50 Acknowledged.
438 const SkIRect& bbox, SkScalar rasterScale); 438 const SkIRect& bbox, SkScalar rasterScale);
439 439
440 bool operator==(const State& b) const; 440 bool operator==(const State& b) const;
441 441
442 SkPDFShader::State* CreateAlphaToLuminosityState() const; 442 SkPDFShader::State* CreateAlphaToLuminosityState() const;
443 SkPDFShader::State* CreateOpaqueState() const; 443 SkPDFShader::State* CreateOpaqueState() const;
444 444
445 bool GradientHasAlpha() const; 445 bool GradientHasAlpha() const;
446 446
447 private: 447 private:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 } else { 508 } else {
509 SkPDFObject* shader = canon->findFunctionShader(state); 509 SkPDFObject* shader = canon->findFunctionShader(state);
510 return shader ? SkRef(shader) 510 return shader ? SkRef(shader)
511 : SkPDFFunctionShader::Create(canon, autoState); 511 : SkPDFFunctionShader::Create(canon, autoState);
512 } 512 }
513 } 513 }
514 514
515 // static 515 // static
516 SkPDFObject* SkPDFShader::GetPDFShader(SkPDFDocument* doc, 516 SkPDFObject* SkPDFShader::GetPDFShader(SkPDFDocument* doc,
517 SkScalar dpi, 517 SkScalar dpi,
518 const SkShader& shader, 518 SkShader* shader,
519 const SkMatrix& matrix, 519 const SkMatrix& matrix,
520 const SkIRect& surfaceBBox, 520 const SkIRect& surfaceBBox,
521 SkScalar rasterScale) { 521 SkScalar rasterScale) {
522 SkAutoTDelete<SkPDFShader::State> state(new State(shader, matrix, surfaceBBo x, rasterScale)); 522 SkAutoTDelete<SkPDFShader::State> state(new State(shader, matrix, surfaceBBo x, rasterScale));
523 return get_pdf_shader_by_state(doc, dpi, &state); 523 return get_pdf_shader_by_state(doc, dpi, &state);
524 } 524 }
525 525
526 static sk_sp<SkPDFDict> get_gradient_resource_dict( 526 static sk_sp<SkPDFDict> get_gradient_resource_dict(
527 SkPDFObject* functionShader, 527 SkPDFObject* functionShader,
528 SkPDFObject* gState) { 528 SkPDFObject* gState) {
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 break; 1082 break;
1083 case SkShader::kSweep_GradientType: 1083 case SkShader::kSweep_GradientType:
1084 case SkShader::kNone_GradientType: 1084 case SkShader::kNone_GradientType:
1085 case SkShader::kColor_GradientType: 1085 case SkShader::kColor_GradientType:
1086 break; 1086 break;
1087 } 1087 }
1088 } 1088 }
1089 return true; 1089 return true;
1090 } 1090 }
1091 1091
1092 SkPDFShader::State::State(const SkShader& shader, const SkMatrix& canvasTransfor m, 1092 SkPDFShader::State::State(SkShader* shader, const SkMatrix& canvasTransform,
1093 const SkIRect& bbox, SkScalar rasterScale) 1093 const SkIRect& bbox, SkScalar rasterScale)
1094 : fCanvasTransform(canvasTransform), 1094 : fCanvasTransform(canvasTransform),
1095 fBBox(bbox), 1095 fBBox(bbox),
1096 fPixelGeneration(0) { 1096 fPixelGeneration(0) {
1097 fInfo.fColorCount = 0; 1097 fInfo.fColorCount = 0;
1098 fInfo.fColors = nullptr; 1098 fInfo.fColors = nullptr;
1099 fInfo.fColorOffsets = nullptr; 1099 fInfo.fColorOffsets = nullptr;
1100 fShaderTransform = shader.getLocalMatrix(); 1100 fShaderTransform = shader->getLocalMatrix();
1101 fImageTileModes[0] = fImageTileModes[1] = SkShader::kClamp_TileMode; 1101 fImageTileModes[0] = fImageTileModes[1] = SkShader::kClamp_TileMode;
1102 1102
1103 fType = shader.asAGradient(&fInfo); 1103 fType = shader->asAGradient(&fInfo);
1104 1104
1105 if (fType == SkShader::kNone_GradientType) { 1105 if (fType == SkShader::kNone_GradientType) {
1106 SkMatrix matrix; 1106 SkMatrix matrix;
1107 if (shader.isABitmap(&fImage, &matrix, fImageTileModes)) { 1107 if (shader->isABitmap(&fImage, &matrix, fImageTileModes)) {
1108 SkASSERT(matrix.isIdentity()); 1108 SkASSERT(matrix.isIdentity());
1109 } else { 1109 } else {
1110 // Generic fallback for unsupported shaders: 1110 // Generic fallback for unsupported shaders:
1111 // * allocate a bbox-sized bitmap 1111 // * allocate a bbox-sized bitmap
1112 // * shade the whole area 1112 // * shade the whole area
1113 // * use the result as a bitmap shader 1113 // * use the result as a bitmap shader
1114 1114
1115 // bbox is in device space. While that's exactly what we want for si zing our bitmap, 1115 // bbox is in device space. While that's exactly what we want for si zing our bitmap,
1116 // we need to map it into shader space for adjustments (to match 1116 // we need to map it into shader space for adjustments (to match
1117 // SkPDFImageShader::Create's behavior). 1117 // SkPDFImageShader::Create's behavior).
(...skipping 12 matching lines...) Expand all
1130 1130
1131 SkISize size = SkISize::Make(SkScalarRoundToInt(rasterScale * bbox.w idth()), 1131 SkISize size = SkISize::Make(SkScalarRoundToInt(rasterScale * bbox.w idth()),
1132 SkScalarRoundToInt(rasterScale * bbox.h eight())); 1132 SkScalarRoundToInt(rasterScale * bbox.h eight()));
1133 SkSize scale = SkSize::Make(SkIntToScalar(size.width()) / shaderRect .width(), 1133 SkSize scale = SkSize::Make(SkIntToScalar(size.width()) / shaderRect .width(),
1134 SkIntToScalar(size.height()) / shaderRec t.height()); 1134 SkIntToScalar(size.height()) / shaderRec t.height());
1135 1135
1136 fImage.allocN32Pixels(size.width(), size.height()); 1136 fImage.allocN32Pixels(size.width(), size.height());
1137 fImage.eraseColor(SK_ColorTRANSPARENT); 1137 fImage.eraseColor(SK_ColorTRANSPARENT);
1138 1138
1139 SkPaint p; 1139 SkPaint p;
1140 p.setShader(const_cast<SkShader*>(&shader)); 1140 p.setShader(sk_ref_sp(shader));
1141 1141
1142 SkCanvas canvas(fImage); 1142 SkCanvas canvas(fImage);
1143 canvas.scale(scale.width(), scale.height()); 1143 canvas.scale(scale.width(), scale.height());
1144 canvas.translate(-shaderRect.x(), -shaderRect.y()); 1144 canvas.translate(-shaderRect.x(), -shaderRect.y());
1145 canvas.drawPaint(p); 1145 canvas.drawPaint(p);
1146 1146
1147 fShaderTransform.setTranslate(shaderRect.x(), shaderRect.y()); 1147 fShaderTransform.setTranslate(shaderRect.x(), shaderRect.y());
1148 fShaderTransform.preScale(1 / scale.width(), 1 / scale.height()); 1148 fShaderTransform.preScale(1 / scale.width(), 1 / scale.height());
1149 } 1149 }
1150 fPixelGeneration = fImage.getGenerationID(); 1150 fPixelGeneration = fImage.getGenerationID();
1151 } else { 1151 } else {
1152 AllocateGradientInfoStorage(); 1152 AllocateGradientInfoStorage();
1153 shader.asAGradient(&fInfo); 1153 shader->asAGradient(&fInfo);
1154 } 1154 }
1155 } 1155 }
1156 1156
1157 SkPDFShader::State::State(const SkPDFShader::State& other) 1157 SkPDFShader::State::State(const SkPDFShader::State& other)
1158 : fType(other.fType), 1158 : fType(other.fType),
1159 fCanvasTransform(other.fCanvasTransform), 1159 fCanvasTransform(other.fCanvasTransform),
1160 fShaderTransform(other.fShaderTransform), 1160 fShaderTransform(other.fShaderTransform),
1161 fBBox(other.fBBox) 1161 fBBox(other.fBBox)
1162 { 1162 {
1163 // Only gradients supported for now, since that is all that is used. 1163 // Only gradients supported for now, since that is all that is used.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 return false; 1225 return false;
1226 } 1226 }
1227 1227
1228 void SkPDFShader::State::AllocateGradientInfoStorage() { 1228 void SkPDFShader::State::AllocateGradientInfoStorage() {
1229 fColorData.set(sk_malloc_throw( 1229 fColorData.set(sk_malloc_throw(
1230 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); 1230 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar))));
1231 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); 1231 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get());
1232 fInfo.fColorOffsets = 1232 fInfo.fColorOffsets =
1233 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); 1233 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount);
1234 } 1234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698