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

Side by Side Diff: gm/path_stroke_with_zero_length.cpp

Issue 1546363002: initialize offscreen in StrokeZeroGM (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 #include "SkPath.h" 8 #include "SkPath.h"
9 #include "SkStream.h" 9 #include "SkStream.h"
10 #include "gm.h" 10 #include "gm.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 SkPaint round(butt); 110 SkPaint round(butt);
111 round.setStrokeCap(SkPaint::kRound_Cap); 111 round.setStrokeCap(SkPaint::kRound_Cap);
112 drawPaths(round, 1 << 7); 112 drawPaths(round, 1 << 7);
113 return; 113 return;
114 } 114 }
115 115
116 SkScalar widths[] = { 0, .999f, 1, 1.001f, 20 }; 116 SkScalar widths[] = { 0, .999f, 1, 1.001f, 20 };
117 bool aliases[] = { false, true }; 117 bool aliases[] = { false, true };
118 for (bool antialias : aliases) { 118 for (bool antialias : aliases) {
119 canvas->save(); 119 canvas->save();
120 for (SkScalar width : widths) { 120 for (SkScalar width : widths) {
121 canvas->save(); 121 canvas->save();
122 SkPaint butt; 122 SkPaint butt;
123 butt.setAntiAlias(antialias); 123 butt.setAntiAlias(antialias);
124 butt.setStyle(SkPaint::kStroke_Style); 124 butt.setStyle(SkPaint::kStroke_Style);
125 butt.setStrokeWidth(width); 125 butt.setStrokeWidth(width);
126 drawPaths(butt, -1); 126 drawPaths(butt, -1);
127 127
128 SkPaint round(butt); 128 SkPaint round(butt);
129 round.setStrokeCap(SkPaint::kRound_Cap); 129 round.setStrokeCap(SkPaint::kRound_Cap);
130 drawPaths(round, -1); 130 drawPaths(round, -1);
131 131
132 SkPaint square(butt); 132 SkPaint square(butt);
133 square.setStrokeCap(SkPaint::kSquare_Cap); 133 square.setStrokeCap(SkPaint::kSquare_Cap);
134 drawPaths(square, -1); 134 drawPaths(square, -1);
135 canvas->restore(); 135 canvas->restore();
136 canvas->translate(220, 0); 136 canvas->translate(220, 0);
137 } 137 }
138 canvas->restore(); 138 canvas->restore();
139 canvas->translate(0, 210); 139 canvas->translate(0, 210);
140 } 140 }
141 } 141 }
142 142
143 private: 143 private:
144 void drawFat(SkCanvas* canvas, const SkPath& path, const SkPaint& paint, int index) { 144 void drawFat(SkCanvas* canvas, const SkPath& path, const SkPaint& paint, int index) {
145 const SkScalar scale = 10; 145 const SkScalar scale = 10;
146 SkRect bounds = path.getBounds(); 146 SkRect bounds = path.getBounds();
147 SkBitmap offscreen; 147 SkBitmap offscreen;
148 offscreen.allocN32Pixels(SkScalarRoundToInt(bounds.width() + 4), 148 offscreen.allocN32Pixels(SkScalarRoundToInt(bounds.width() + 4),
149 SkScalarRoundToInt(bounds.height() + 4)); 149 SkScalarRoundToInt(bounds.height() + 4));
150 offscreen.eraseColor(SK_ColorWHITE);
150 SkScalar pathX = bounds.fLeft - 2; 151 SkScalar pathX = bounds.fLeft - 2;
151 SkScalar pathY = bounds.fTop - 2; 152 SkScalar pathY = bounds.fTop - 2;
152 SkMatrix cMatrix = canvas->getTotalMatrix(); 153 SkMatrix cMatrix = canvas->getTotalMatrix();
153 if (!canvas->readPixels(&offscreen, SkScalarRoundToInt(pathX + cMatrix.g etTranslateX()), 154 if (!canvas->readPixels(&offscreen, SkScalarRoundToInt(pathX + cMatrix.g etTranslateX()),
154 SkScalarRoundToInt(pathY + cMatrix.getTranslateY()))) { 155 SkScalarRoundToInt(pathY + cMatrix.getTranslateY()))) {
155 return; 156 return;
156 } 157 }
157 158
158 canvas->save(); 159 canvas->save();
159 SkMatrix clipM; 160 SkMatrix clipM;
(...skipping 26 matching lines...) Expand all
186 canvas->restore(); 187 canvas->restore();
187 } 188 }
188 } 189 }
189 190
190 }; 191 };
191 192
192 /////////////////////////////////////////////////////////////////////////////// 193 ///////////////////////////////////////////////////////////////////////////////
193 194
194 DEF_GM( return new StrokeZeroGM(); ) 195 DEF_GM( return new StrokeZeroGM(); )
195 196
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