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" |
11 #include "SkShadowShader.h" | 11 #include "SkShadowShader.h" |
12 #include "SkSurface.h" | 12 #include "SkSurface.h" |
13 | 13 |
14 #ifdef SK_EXPERIMENTAL_SHADOWING | 14 #ifdef SK_EXPERIMENTAL_SHADOWING |
15 | 15 |
16 class ShadowingView : public SampleView { | 16 class ShadowingView : public SampleView { |
17 public: | 17 public: |
18 ShadowingView() | 18 ShadowingView() |
19 : fSceneChanged(true) | 19 : fSceneChanged(true) |
20 , fLightsChanged(true) | 20 , fLightsChanged(true) |
21 , fMoveLight(false) | 21 , fMoveLight(false) |
22 , fClearShadowMaps(false) | 22 , fClearShadowMaps(false) |
23 , fSelectedRectID(-1) | 23 , fSelectedRectID(-1) |
24 , fSelectedSliderID(-1) | 24 , fSelectedSliderID(-1) |
25 , fLightDepth(300.0f) { | 25 , fLightDepth(600.0f) { |
26 this->setBGColor(0xFFCCCCCC); | 26 this->setBGColor(0xFFCCCCCC); |
27 | 27 |
28 this->updateLights(200, 200); | 28 this->updateLights(200, 200); |
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(200,150,350,300); |
33 | 33 |
34 fTestRects[1].fColor = 0xFF88EE88; | 34 fTestRects[1].fColor = 0xFF88EE88; |
35 fTestRects[1].fDepth = 160; | 35 fTestRects[1].fDepth = 160; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 case 'd': | 73 case 'd': |
74 // Raster generated shadow maps have their origin in the UL
corner | 74 // Raster generated shadow maps have their origin in the UL
corner |
75 // GPU shadow maps can have an arbitrary origin. | 75 // GPU shadow maps can have an arbitrary origin. |
76 // We override the 'd' keypress so that when the device is c
ycled, | 76 // We override the 'd' keypress so that when the device is c
ycled, |
77 // the shadow maps will be re-generated according to the new
backend. | 77 // the shadow maps will be re-generated according to the new
backend. |
78 fClearShadowMaps = true; | 78 fClearShadowMaps = true; |
79 break; | 79 break; |
80 case 'q': | 80 case 'q': |
81 fLightDepth += 5.0f; | 81 fLightDepth += 5.0f; |
82 fMoveLight = true; | 82 fMoveLight = true; |
| 83 break; |
83 case 'B': | 84 case 'B': |
84 if (SkShadowParams::kVariance_ShadowType == fShadowParams.fT
ype) { | 85 if (SkShadowParams::kVariance_ShadowType == fShadowParams.fT
ype) { |
85 fShadowParams.fType = SkShadowParams::kNoBlur_ShadowType
; | 86 fShadowParams.fType = SkShadowParams::kNoBlur_ShadowType
; |
86 } else if (SkShadowParams::kNoBlur_ShadowType == | 87 } else if (SkShadowParams::kNoBlur_ShadowType == |
87 fShadowParams.fType) { | 88 fShadowParams.fType) { |
88 fShadowParams.fType = SkShadowParams::kVariance_ShadowTy
pe; | 89 fShadowParams.fType = SkShadowParams::kVariance_ShadowTy
pe; |
89 } | 90 } |
90 fLightsChanged = true; | 91 fLightsChanged = true; |
91 break; | 92 break; |
92 case 'w': | 93 case 'w': |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { | 159 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { |
159 return new SkView::Click(this); | 160 return new SkView::Click(this); |
160 } | 161 } |
161 | 162 |
162 void updateLights(int x, int y) { | 163 void updateLights(int x, int y) { |
163 SkLights::Builder builder; | 164 SkLights::Builder builder; |
164 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.2f, 0.4f, 0.6f)
, | 165 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.2f, 0.4f, 0.6f)
, |
165 SkVector3::Make(x - 50, | 166 SkVector3::Make(x - 50, |
166 350 - y, | 167 350 - y, |
167 fLightDepth), | 168 fLightDepth), |
168 1024)); | 169 100000)); |
169 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.6f, 0.4f, 0.2f)
, | 170 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.6f, 0.4f, 0.2f)
, |
170 SkVector3::Make(x + 50, | 171 SkVector3::Make(x + 50, |
171 450 - y, | 172 450 - y, |
172 fLightDepth), | 173 fLightDepth), |
173 1024)); | 174 100000)); |
174 builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.2f, 0.2f,
0.2f), | 175 builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.2f, 0.2f,
0.2f), |
175 SkVector3::Make(0.2f, 0.2f,
1.0f))); | 176 SkVector3::Make(0.2f, 0.2f,
1.0f))); |
176 fLights = builder.finish(); | 177 fLights = builder.finish(); |
177 } | 178 } |
178 | 179 |
179 void updateFromSelectedSlider() { | 180 void updateFromSelectedSlider() { |
180 SkScalar newValue = fSliders[fSelectedSliderID].fGeometry.fLeft * | 181 SkScalar newValue = fSliders[fSelectedSliderID].fGeometry.fLeft * |
181 fSliders[fSelectedSliderID].fScale + | 182 fSliders[fSelectedSliderID].fScale + |
182 fSliders[fSelectedSliderID].fOffset; | 183 fSliders[fSelectedSliderID].fOffset; |
183 | 184 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 sk_sp<SkLights> fLights; | 299 sk_sp<SkLights> fLights; |
299 | 300 |
300 typedef SampleView INHERITED; | 301 typedef SampleView INHERITED; |
301 }; | 302 }; |
302 | 303 |
303 ////////////////////////////////////////////////////////////////////////////// | 304 ////////////////////////////////////////////////////////////////////////////// |
304 static SkView* MyFactory() { return new ShadowingView; } | 305 static SkView* MyFactory() { return new ShadowingView; } |
305 static SkViewRegister reg(MyFactory); | 306 static SkViewRegister reg(MyFactory); |
306 | 307 |
307 #endif | 308 #endif |
OLD | NEW |