OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 | 9 |
10 #include "SkLightingShader.h" | 10 #include "SkLightingShader.h" |
11 #include "SkPoint3.h" | 11 #include "SkPoint3.h" |
12 #include "SkShader.h" | 12 #include "SkShader.h" |
13 | 13 |
14 static SkBitmap make_checkerboard(int texSize) { | |
15 SkBitmap bitmap; | |
16 bitmap.allocN32Pixels(texSize, texSize); | |
17 | |
18 SkCanvas canvas(bitmap); | |
19 sk_tool_utils::draw_checkerboard(&canvas, | |
20 sk_tool_utils::color_to_565(0x0), | |
21 sk_tool_utils::color_to_565(0xFF804020), | |
22 8); | |
23 return bitmap; | |
24 } | |
25 | |
26 // Create a hemispherical normal map | 14 // Create a hemispherical normal map |
27 static SkBitmap make_hemi_normalmap(int texSize) { | 15 static SkBitmap make_hemi_normalmap(int texSize) { |
28 SkBitmap hemi; | 16 SkBitmap hemi; |
29 hemi.allocN32Pixels(texSize, texSize); | 17 hemi.allocN32Pixels(texSize, texSize); |
30 | 18 |
31 sk_tool_utils::create_hemi_normal_map(&hemi, SkIRect::MakeWH(texSize, texSiz
e)); | 19 sk_tool_utils::create_hemi_normal_map(&hemi, SkIRect::MakeWH(texSize, texSiz
e)); |
32 return hemi; | 20 return hemi; |
33 } | 21 } |
34 | 22 |
35 // Create a truncated pyramid normal map | 23 // Create a truncated pyramid normal map |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 68 |
81 SkString onShortName() override { | 69 SkString onShortName() override { |
82 return SkString("lightingshader"); | 70 return SkString("lightingshader"); |
83 } | 71 } |
84 | 72 |
85 SkISize onISize() override { | 73 SkISize onISize() override { |
86 return SkISize::Make(kGMSize, kGMSize); | 74 return SkISize::Make(kGMSize, kGMSize); |
87 } | 75 } |
88 | 76 |
89 void onOnceBeforeDraw() override { | 77 void onOnceBeforeDraw() override { |
90 fDiffuse = make_checkerboard(kTexSize); | 78 fDiffuse = sk_tool_utils::create_checkerboard_bitmap( |
| 79 kTexSize, kTexSize, |
| 80 sk_tool_utils::color_to_
565(0x0), |
| 81 sk_tool_utils::color_to_
565(0xFF804020), |
| 82 8); |
91 | 83 |
92 fNormalMaps[kHemi_NormalMap] = make_hemi_normalmap(kTexSize); | 84 fNormalMaps[kHemi_NormalMap] = make_hemi_normalmap(kTexSize); |
93 fNormalMaps[kFrustum_NormalMap] = make_frustum_normalmap(kTexSize); | 85 fNormalMaps[kFrustum_NormalMap] = make_frustum_normalmap(kTexSize); |
94 fNormalMaps[kTetra_NormalMap] = make_tetra_normalmap(kTexSize); | 86 fNormalMaps[kTetra_NormalMap] = make_tetra_normalmap(kTexSize); |
95 } | 87 } |
96 | 88 |
97 void drawRect(SkCanvas* canvas, const SkRect& r, NormalMap mapType) { | 89 void drawRect(SkCanvas* canvas, const SkRect& r, NormalMap mapType) { |
98 | 90 |
99 SkRect bitmapBounds = SkRect::MakeIWH(fDiffuse.width(), fDiffuse.height(
)); | 91 SkRect bitmapBounds = SkRect::MakeIWH(fDiffuse.width(), fDiffuse.height(
)); |
100 | 92 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 172 |
181 SkAutoTUnref<const SkLightingShader::Lights> fLights; | 173 SkAutoTUnref<const SkLightingShader::Lights> fLights; |
182 | 174 |
183 typedef GM INHERITED; | 175 typedef GM INHERITED; |
184 }; | 176 }; |
185 | 177 |
186 ////////////////////////////////////////////////////////////////////////////// | 178 ////////////////////////////////////////////////////////////////////////////// |
187 | 179 |
188 DEF_GM(return new LightingShaderGM;) | 180 DEF_GM(return new LightingShaderGM;) |
189 } | 181 } |
OLD | NEW |