OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkPictureRecorder.h" | 9 #include "SkPictureRecorder.h" |
10 #include "SkShadowPaintFilterCanvas.h" | 10 #include "SkShadowPaintFilterCanvas.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 , fClearShadowMaps(false) | 22 , fClearShadowMaps(false) |
23 , fSelectedRectID(-1) | 23 , fSelectedRectID(-1) |
24 , fSelectedSliderID(-1) | 24 , fSelectedSliderID(-1) |
25 , fLightDepth(400.0f) { | 25 , fLightDepth(400.0f) { |
26 this->setBGColor(0xFFCCCCCC); | 26 this->setBGColor(0xFFCCCCCC); |
27 | 27 |
28 this->updateLights(100, 100); | 28 this->updateLights(100, 100); |
29 | 29 |
30 fTestRects[0].fColor = 0xFFEE8888; | 30 fTestRects[0].fColor = 0xFFEE8888; |
31 fTestRects[0].fDepth = 80; | 31 fTestRects[0].fDepth = 80; |
32 fTestRects[0].fGeometry = SkRect::MakeLTRB(200,150,350,300); | 32 fTestRects[0].fGeometry = SkRect::MakeLTRB(300,200,350,250); |
33 | 33 |
34 fTestRects[1].fColor = 0xFF88EE88; | 34 fTestRects[1].fColor = 0xFF88EE88; |
35 fTestRects[1].fDepth = 160; | 35 fTestRects[1].fDepth = 160; |
36 fTestRects[1].fGeometry = SkRect::MakeLTRB(150,200,300,350); | 36 fTestRects[1].fGeometry = SkRect::MakeLTRB(200,300,250,350); |
37 | 37 |
38 fTestRects[2].fColor = 0xFF8888EE; | 38 fTestRects[2].fColor = 0xFF8888EE; |
39 fTestRects[2].fDepth = 240; | 39 fTestRects[2].fDepth = 240; |
40 fTestRects[2].fGeometry = SkRect::MakeLTRB(100,100,250,250); | 40 fTestRects[2].fGeometry = SkRect::MakeLTRB(100,100,150,150); |
41 | 41 |
42 fSliders[0].fGeometry = SkRect::MakeLTRB(20, 400, 30, 420); | 42 fSliders[0].fGeometry = SkRect::MakeLTRB(20, 400, 30, 420); |
43 fSliders[0].fOffset = 0.0f; | 43 fSliders[0].fOffset = 0.0f; |
44 fSliders[0].fScale = 0.1f; | 44 fSliders[0].fScale = 0.1f; |
45 | 45 |
46 fSliders[1].fGeometry = SkRect::MakeLTRB(100, 420, 110, 440); | 46 fSliders[1].fGeometry = SkRect::MakeLTRB(100, 420, 110, 440); |
47 fSliders[1].fOffset = 0.0f; | 47 fSliders[1].fOffset = 0.0f; |
48 fSliders[1].fScale = 10.0f; | 48 fSliders[1].fScale = 10.0f; |
49 | 49 |
50 fSliders[2].fGeometry = SkRect::MakeLTRB(0, 440, 10, 460); | 50 fSliders[2].fGeometry = SkRect::MakeLTRB(0, 440, 10, 460); |
51 fSliders[2].fOffset = 0.0f; | 51 fSliders[2].fOffset = 0.0f; |
52 fSliders[2].fScale = 0.0025f; | 52 fSliders[2].fScale = 0.0025f; |
53 | 53 |
54 fShadowParams.fShadowRadius = 4.0f; | 54 fShadowParams.fShadowRadius = 4.0f; |
55 fShadowParams.fBiasingConstant = 0.3f; | 55 fShadowParams.fBiasingConstant = 0.3f; |
56 fShadowParams.fMinVariance = 2048; // we need a higher min variance for
point lights | 56 fShadowParams.fMinVariance = 2048; // we need a higher min variance for
point lights |
57 fShadowParams.fType = SkShadowParams::kVariance_ShadowType; | 57 fShadowParams.fType = SkShadowParams::kNoBlur_ShadowType; |
58 } | 58 } |
59 | 59 |
60 protected: | 60 protected: |
61 bool onQuery(SkEvent *evt) override { | 61 bool onQuery(SkEvent *evt) override { |
62 if (SampleCode::TitleQ(*evt)) { | 62 if (SampleCode::TitleQ(*evt)) { |
63 SampleCode::TitleR(evt, "shadowing"); | 63 SampleCode::TitleR(evt, "shadowing"); |
64 return true; | 64 return true; |
65 } | 65 } |
66 | 66 |
67 SkUnichar uni; | 67 SkUnichar uni; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 canvas->drawRect(fSliders[i].fGeometry, paint); | 155 canvas->drawRect(fSliders[i].fGeometry, paint); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { | 159 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { |
160 return new SkView::Click(this); | 160 return new SkView::Click(this); |
161 } | 161 } |
162 | 162 |
163 void updateLights(int x, int y) { | 163 void updateLights(int x, int y) { |
164 SkLights::Builder builder; | 164 SkLights::Builder builder; |
165 builder.setAmbientLightColor(SkColor3f::Make(0.2f, 0.2f, 0.2f)); | 165 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(1.0f, 1.0f, 1.0f)
, |
166 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.2f, 0.4f, 0.6f)
, | 166 SkVector3::Make(x, |
167 SkVector3::Make(x - 50, | 167 kHeight - y, |
168 350 - y, | |
169 fLightDepth), | 168 fLightDepth), |
170 100000)); | 169 100000, true)); |
171 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.6f, 0.4f, 0.2f)
, | |
172 SkVector3::Make(x + 50, | |
173 450 - y, | |
174 fLightDepth), | |
175 100000)); | |
176 fLights = builder.finish(); | 170 fLights = builder.finish(); |
177 } | 171 } |
178 | 172 |
179 void updateFromSelectedSlider() { | 173 void updateFromSelectedSlider() { |
180 SkScalar newValue = fSliders[fSelectedSliderID].fGeometry.fLeft * | 174 SkScalar newValue = fSliders[fSelectedSliderID].fGeometry.fLeft * |
181 fSliders[fSelectedSliderID].fScale + | 175 fSliders[fSelectedSliderID].fScale + |
182 fSliders[fSelectedSliderID].fOffset; | 176 fSliders[fSelectedSliderID].fOffset; |
183 | 177 |
184 switch (fSelectedSliderID) { | 178 switch (fSelectedSliderID) { |
185 case 0: | 179 case 0: |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 sk_sp<SkLights> fLights; | 292 sk_sp<SkLights> fLights; |
299 | 293 |
300 typedef SampleView INHERITED; | 294 typedef SampleView INHERITED; |
301 }; | 295 }; |
302 | 296 |
303 ////////////////////////////////////////////////////////////////////////////// | 297 ////////////////////////////////////////////////////////////////////////////// |
304 static SkView* MyFactory() { return new ShadowingView; } | 298 static SkView* MyFactory() { return new ShadowingView; } |
305 static SkViewRegister reg(MyFactory); | 299 static SkViewRegister reg(MyFactory); |
306 | 300 |
307 #endif | 301 #endif |
OLD | NEW |