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

Side by Side Diff: gm/lighting.cpp

Issue 1870133003: Make some GMs animate (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix bugs Created 4 years, 8 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 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "SkLightingImageFilter.h" 9 #include "SkLightingImageFilter.h"
10 #include "SkOffsetImageFilter.h" 10 #include "SkOffsetImageFilter.h"
11 #include "SkPoint3.h" 11 #include "SkPoint3.h"
12 12
13 #define WIDTH 330 13 #define WIDTH 330
14 #define HEIGHT 660 14 #define HEIGHT 660
15 15
16 namespace skiagm { 16 namespace skiagm {
17 17
18 class ImageLightingGM : public GM { 18 class ImageLightingGM : public GM {
19 public: 19 public:
20 ImageLightingGM() { 20 ImageLightingGM()
21 : fAzimuth(225) {
21 this->setBGColor(0xFF000000); 22 this->setBGColor(0xFF000000);
22 } 23 }
23 24
24 protected: 25 protected:
25 26
26 SkString onShortName() override { 27 SkString onShortName() override {
27 return SkString("lighting"); 28 return SkString("lighting");
28 } 29 }
29 30
30 SkISize onISize() override { 31 SkISize onISize() override {
(...skipping 19 matching lines...) Expand all
50 checkPaint.setColor(sk_tool_utils::color_to_565(0xFF202020)); 51 checkPaint.setColor(sk_tool_utils::color_to_565(0xFF202020));
51 for (int y = 0; y < HEIGHT; y += 16) { 52 for (int y = 0; y < HEIGHT; y += 16) {
52 for (int x = 0; x < WIDTH; x += 16) { 53 for (int x = 0; x < WIDTH; x += 16) {
53 canvas->save(); 54 canvas->save();
54 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 55 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
55 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), checkPaint); 56 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), checkPaint);
56 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), checkPaint); 57 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), checkPaint);
57 canvas->restore(); 58 canvas->restore();
58 } 59 }
59 } 60 }
60 SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10)); 61 SkScalar cosAzimuth;
61 SkScalar azimuthRad = SkDegreesToRadians(SkIntToScalar(225)); 62 SkScalar sinAzimuth = SkScalarSinCos(SkDegreesToRadians(fAzimuth), &cosA zimuth);
63
64 SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40 ), 0);
65 SkPoint3 spotLocation = SkPoint3::Make(spotTarget.fX + 70.7214f * cosAzi muth,
66 spotTarget.fY + 70.7214f * sinAzi muth,
67 spotTarget.fZ + SkIntToScalar(20) );
68 SkScalar spotExponent = SK_Scalar1;
69
70 SkPoint3 pointLocation = SkPoint3::Make(spotTarget.fX + 50 * cosAzimuth,
71 spotTarget.fY + 50 * sinAzimuth,
72 SkIntToScalar(10));
62 SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5)); 73 SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5));
63 SkPoint3 distantDirection = SkPoint3::Make(SkScalarMul(SkScalarCos(azimu thRad), 74
75 SkPoint3 distantDirection = SkPoint3::Make(SkScalarMul(cosAzimuth,
64 SkScalarCos(eleva tionRad)), 76 SkScalarCos(eleva tionRad)),
65 SkScalarMul(SkScalarSin(azimu thRad), 77 SkScalarMul(sinAzimuth,
66 SkScalarCos(eleva tionRad)), 78 SkScalarCos(eleva tionRad)),
67 SkScalarSin(elevationRad)); 79 SkScalarSin(elevationRad));
68 SkPoint3 spotLocation = SkPoint3::Make(SkIntToScalar(-10),
69 SkIntToScalar(-10),
70 SkIntToScalar(20));
71 SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40 ), 0);
72 SkScalar spotExponent = SK_Scalar1;
73 SkScalar cutoffAngle = SkIntToScalar(15); 80 SkScalar cutoffAngle = SkIntToScalar(15);
74 SkScalar kd = SkIntToScalar(2); 81 SkScalar kd = SkIntToScalar(2);
75 SkScalar ks = SkIntToScalar(1); 82 SkScalar ks = SkIntToScalar(1);
76 SkScalar shininess = SkIntToScalar(8); 83 SkScalar shininess = SkIntToScalar(8);
77 SkScalar surfaceScale = SkIntToScalar(1); 84 SkScalar surfaceScale = SkIntToScalar(1);
78 SkColor white(0xFFFFFFFF); 85 SkColor white(0xFFFFFFFF);
79 SkPaint paint; 86 SkPaint paint;
80 87
81 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65)); 88 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65));
82 SkImageFilter::CropRect fullSizeCropRect(SkRect::MakeXYWH(0, 0, 100, 100 )); 89 SkImageFilter::CropRect fullSizeCropRect(SkRect::MakeXYWH(0, 0, 100, 100 ));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 ks , 149 ks ,
143 sh ininess, 150 sh ininess,
144 in put, 151 in put,
145 cr ))->unref(); 152 cr ))->unref();
146 drawClippedBitmap(canvas, paint, 220, y); 153 drawClippedBitmap(canvas, paint, 220, y);
147 154
148 y += 110; 155 y += 110;
149 } 156 }
150 } 157 }
151 158
159 bool onAnimate(const SkAnimTimer& timer) override {
160 fAzimuth = (fAzimuth + 2) % 360;
161 return true;
162 }
163
152 private: 164 private:
153 SkBitmap fBitmap; 165 SkBitmap fBitmap;
166 int fAzimuth;
154 167
155 typedef GM INHERITED; 168 typedef GM INHERITED;
156 }; 169 };
157 170
158 ////////////////////////////////////////////////////////////////////////////// 171 //////////////////////////////////////////////////////////////////////////////
159 172
160 DEF_GM(return new ImageLightingGM;) 173 DEF_GM(return new ImageLightingGM;)
161 } 174 }
OLDNEW
« gm/dashcircle.cpp ('K') | « gm/dashcircle.cpp ('k') | gm/stringart.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698