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

Side by Side Diff: gm/hairmodes.cpp

Issue 1793303002: Reland of "more shader-->sp conversions (patchset #5 id:80001 of https://codereview.chromium… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make pictureRef a value, so its clearer what's going on 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
« no previous file with comments | « gm/gradtext.cpp ('k') | gm/imagefiltersclipped.cpp » ('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 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 for (int angle = 0; angle < 24; ++angle) { 51 for (int angle = 0; angle < 24; ++angle) {
52 SkScalar x = SkScalarCos(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gWidth; 52 SkScalar x = SkScalarCos(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gWidth;
53 SkScalar y = SkScalarSin(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gHeight; 53 SkScalar y = SkScalarSin(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gHeight;
54 paint.setStrokeWidth(SK_Scalar1 * angle * 2 / 24); 54 paint.setStrokeWidth(SK_Scalar1 * angle * 2 / 24);
55 canvas->drawLine(W/2, H/2, W/2 + x, H/2 + y, paint); 55 canvas->drawLine(W/2, H/2, W/2 + x, H/2 + y, paint);
56 } 56 }
57 57
58 return H; 58 return H;
59 } 59 }
60 60
61 static SkShader* make_bg_shader() { 61 static sk_sp<SkShader> make_bg_shader() {
62 SkBitmap bm; 62 SkBitmap bm;
63 bm.allocN32Pixels(2, 2); 63 bm.allocN32Pixels(2, 2);
64 *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = 0xFFFFFFFF; 64 *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = 0xFFFFFFFF;
65 *bm.getAddr32(1, 0) = *bm.getAddr32(0, 1) = SkPackARGB32(0xFF, 0xCE, 0xCF, 0 xCE); 65 *bm.getAddr32(1, 0) = *bm.getAddr32(0, 1) = SkPackARGB32(0xFF, 0xCE, 0xCF, 0 xCE);
66 66
67 SkMatrix m; 67 SkMatrix m;
68 m.setScale(SkIntToScalar(6), SkIntToScalar(6)); 68 m.setScale(SkIntToScalar(6), SkIntToScalar(6));
69 return SkShader::CreateBitmapShader(bm, 69 return SkShader::MakeBitmapShader(bm,
70 SkShader::kRepeat_TileMode, 70 SkShader::kRepeat_TileMode, SkShader::kRep eat_TileMode, &m);
71 SkShader::kRepeat_TileMode,
72 &m);
73 } 71 }
74 72
75 namespace skiagm { 73 namespace skiagm {
76 74
77 class HairModesGM : public GM { 75 class HairModesGM : public GM {
78 SkPaint fBGPaint; 76 SkPaint fBGPaint;
79 77
80 protected: 78 protected:
81 SkString onShortName() override { 79 SkString onShortName() override {
82 return SkString("hairmodes"); 80 return SkString("hairmodes");
83 } 81 }
84 82
85 virtual SkISize onISize() override { return SkISize::Make(640, 480); } 83 virtual SkISize onISize() override { return SkISize::Make(640, 480); }
86 84
87 void onOnceBeforeDraw() override { 85 void onOnceBeforeDraw() override {
88 fBGPaint.setShader(make_bg_shader())->unref(); 86 fBGPaint.setShader(make_bg_shader());
89 } 87 }
90 88
91 void onDraw(SkCanvas* canvas) override { 89 void onDraw(SkCanvas* canvas) override {
92 const SkRect bounds = SkRect::MakeWH(W, H); 90 const SkRect bounds = SkRect::MakeWH(W, H);
93 static const SkAlpha gAlphaValue[] = { 0xFF, 0x88, 0x88 }; 91 static const SkAlpha gAlphaValue[] = { 0xFF, 0x88, 0x88 };
94 92
95 canvas->translate(SkIntToScalar(4), SkIntToScalar(4)); 93 canvas->translate(SkIntToScalar(4), SkIntToScalar(4));
96 94
97 for (int alpha = 0; alpha < 4; ++alpha) { 95 for (int alpha = 0; alpha < 4; ++alpha) {
98 canvas->save(); 96 canvas->save();
(...skipping 25 matching lines...) Expand all
124 private: 122 private:
125 typedef GM INHERITED; 123 typedef GM INHERITED;
126 }; 124 };
127 125
128 //////////////////////////////////////////////////////////////////////////// // 126 //////////////////////////////////////////////////////////////////////////// //
129 127
130 static GM* MyFactory(void*) { return new HairModesGM; } 128 static GM* MyFactory(void*) { return new HairModesGM; }
131 static GMRegistry reg(MyFactory); 129 static GMRegistry reg(MyFactory);
132 130
133 } 131 }
OLDNEW
« no previous file with comments | « gm/gradtext.cpp ('k') | gm/imagefiltersclipped.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698