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

Side by Side Diff: gm/convexpolyclip.cpp

Issue 1238483002: make convex poly clip portable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 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 #include "gm.h" 9 #include "gm.h"
10 10
11 #include "SkBitmap.h" 11 #include "SkBitmap.h"
12 #include "SkGradientShader.h" 12 #include "SkGradientShader.h"
13 #include "SkTLList.h" 13 #include "SkTLList.h"
14 14
15 static SkBitmap make_bmp(int w, int h) { 15 static SkBitmap make_bmp(int w, int h) {
16 SkBitmap bmp; 16 SkBitmap bmp;
17 bmp.allocN32Pixels(w, h, true); 17 bmp.allocN32Pixels(w, h, true);
18 18
19 SkCanvas canvas(bmp); 19 SkCanvas canvas(bmp);
20 SkScalar wScalar = SkIntToScalar(w); 20 SkScalar wScalar = SkIntToScalar(w);
21 SkScalar hScalar = SkIntToScalar(h); 21 SkScalar hScalar = SkIntToScalar(h);
22 22
23 SkPoint pt = { wScalar / 2, hScalar / 2 }; 23 SkPoint pt = { wScalar / 2, hScalar / 2 };
24 24
25 SkScalar radius = 3 * SkMaxScalar(wScalar, hScalar); 25 SkScalar radius = 3 * SkMaxScalar(wScalar, hScalar);
26 26
27 SkColor colors[] = { SK_ColorDKGRAY, 0xFF222255, 27 SkColor colors[] = { sk_tool_utils::color_to_565(SK_ColorDKGRAY),
28 0xFF331133, 0xFF884422, 28 sk_tool_utils::color_to_565(0xFF222255),
29 0xFF000022, SK_ColorWHITE, 29 sk_tool_utils::color_to_565(0xFF331133),
30 0xFFAABBCC}; 30 sk_tool_utils::color_to_565(0xFF884422),
31 sk_tool_utils::color_to_565(0xFF000022), SK_ColorWH ITE,
32 sk_tool_utils::color_to_565(0xFFAABBCC) };
31 33
32 SkScalar pos[] = {0, 34 SkScalar pos[] = {0,
33 SK_Scalar1 / 6, 35 SK_Scalar1 / 6,
34 2 * SK_Scalar1 / 6, 36 2 * SK_Scalar1 / 6,
35 3 * SK_Scalar1 / 6, 37 3 * SK_Scalar1 / 6,
36 4 * SK_Scalar1 / 6, 38 4 * SK_Scalar1 / 6,
37 5 * SK_Scalar1 / 6, 39 5 * SK_Scalar1 / 6,
38 SK_Scalar1}; 40 SK_Scalar1};
39 41
40 SkPaint paint; 42 SkPaint paint;
41 SkRect rect = SkRect::MakeWH(wScalar, hScalar); 43 SkRect rect = SkRect::MakeWH(wScalar, hScalar);
42 SkMatrix mat = SkMatrix::I(); 44 SkMatrix mat = SkMatrix::I();
43 for (int i = 0; i < 4; ++i) { 45 for (int i = 0; i < 4; ++i) {
44 paint.setShader(SkGradientShader::CreateRadial( 46 paint.setShader(SkGradientShader::CreateRadial(
45 pt, radius, 47 pt, radius,
46 colors, pos, 48 colors, pos,
47 SK_ARRAY_COUNT(colors), 49 SK_ARRAY_COUNT(colors),
48 SkShader::kRepeat_TileMode, 50 SkShader::kRepeat_TileMode,
49 0, &mat))->unref(); 51 0, &mat))->unref();
50 canvas.drawRect(rect, paint); 52 canvas.drawRect(rect, paint);
51 rect.inset(wScalar / 8, hScalar / 8); 53 rect.inset(wScalar / 8, hScalar / 8);
52 mat.preTranslate(6 * wScalar, 6 * hScalar); 54 mat.preTranslate(6 * wScalar, 6 * hScalar);
53 mat.postScale(SK_Scalar1 / 3, SK_Scalar1 / 3); 55 mat.postScale(SK_Scalar1 / 3, SK_Scalar1 / 3);
54 } 56 }
55 57
56 paint.setAntiAlias(true); 58 paint.setAntiAlias(true);
57 sk_tool_utils::set_portable_typeface(&paint); 59 sk_tool_utils::set_portable_typeface_always(&paint);
58 paint.setTextSize(wScalar / 2.2f); 60 paint.setTextSize(wScalar / 2.2f);
59 paint.setShader(0); 61 paint.setShader(0);
60 paint.setColor(SK_ColorLTGRAY); 62 paint.setColor(sk_tool_utils::color_to_565(SK_ColorLTGRAY));
61 static const char kTxt[] = "Skia"; 63 static const char kTxt[] = "Skia";
62 SkPoint texPos = { wScalar / 17, hScalar / 2 + paint.getTextSize() / 2.5f }; 64 SkPoint texPos = { wScalar / 17, hScalar / 2 + paint.getTextSize() / 2.5f };
63 canvas.drawText(kTxt, SK_ARRAY_COUNT(kTxt)-1, texPos.fX, texPos.fY, paint); 65 canvas.drawText(kTxt, SK_ARRAY_COUNT(kTxt)-1, texPos.fX, texPos.fY, paint);
64 paint.setColor(SK_ColorBLACK); 66 paint.setColor(SK_ColorBLACK);
65 paint.setStyle(SkPaint::kStroke_Style); 67 paint.setStyle(SkPaint::kStroke_Style);
66 paint.setStrokeWidth(SK_Scalar1); 68 paint.setStrokeWidth(SK_Scalar1);
67 canvas.drawText(kTxt, SK_ARRAY_COUNT(kTxt)-1, texPos.fX, texPos.fY, paint); 69 canvas.drawText(kTxt, SK_ARRAY_COUNT(kTxt)-1, texPos.fX, texPos.fY, paint);
68 return bmp; 70 return bmp;
69 } 71 }
70 72
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 bgPaint.setAlpha(0x15); 145 bgPaint.setAlpha(0x15);
144 SkISize size = canvas->getDeviceSize(); 146 SkISize size = canvas->getDeviceSize();
145 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(size.fWidth), 147 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(size.fWidth),
146 SkIntToScalar(size.fHeight)); 148 SkIntToScalar(size.fHeight));
147 canvas->drawBitmapRectToRect(fBmp, NULL, dstRect, &bgPaint); 149 canvas->drawBitmapRectToRect(fBmp, NULL, dstRect, &bgPaint);
148 150
149 static const char kTxt[] = "Clip Me!"; 151 static const char kTxt[] = "Clip Me!";
150 SkPaint txtPaint; 152 SkPaint txtPaint;
151 txtPaint.setTextSize(23.f); 153 txtPaint.setTextSize(23.f);
152 txtPaint.setAntiAlias(true); 154 txtPaint.setAntiAlias(true);
153 sk_tool_utils::set_portable_typeface(&txtPaint); 155 sk_tool_utils::set_portable_typeface_always(&txtPaint);
154 txtPaint.setColor(SK_ColorDKGRAY); 156 txtPaint.setColor(sk_tool_utils::color_to_565(SK_ColorDKGRAY));
155 SkScalar textW = txtPaint.measureText(kTxt, SK_ARRAY_COUNT(kTxt)-1); 157 SkScalar textW = txtPaint.measureText(kTxt, SK_ARRAY_COUNT(kTxt)-1);
156 158
157 SkScalar startX = 0; 159 SkScalar startX = 0;
158 int testLayers = kBench_Mode != this->getMode(); 160 int testLayers = kBench_Mode != this->getMode();
159 for (int doLayer = 0; doLayer <= testLayers; ++doLayer) { 161 for (int doLayer = 0; doLayer <= testLayers; ++doLayer) {
160 for (SkTLList<Clip>::Iter iter(fClips, SkTLList<Clip>::Iter::kHead_I terStart); 162 for (SkTLList<Clip>::Iter iter(fClips, SkTLList<Clip>::Iter::kHead_I terStart);
161 iter.get(); 163 iter.get();
162 iter.next()) { 164 iter.next()) {
163 const Clip* clip = iter.get(); 165 const Clip* clip = iter.get();
164 SkScalar x = startX; 166 SkScalar x = startX;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 294
293 SkTLList<Clip> fClips; 295 SkTLList<Clip> fClips;
294 SkBitmap fBmp; 296 SkBitmap fBmp;
295 297
296 typedef GM INHERITED; 298 typedef GM INHERITED;
297 }; 299 };
298 300
299 DEF_GM( return SkNEW(ConvexPolyClip); ) 301 DEF_GM( return SkNEW(ConvexPolyClip); )
300 302
301 } 303 }
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