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 "SkBitmapProcShader.h" | 10 #include "SkBitmapProcShader.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 void drawRect(SkCanvas* canvas, const SkRect& r, NormalMap mapType) { | 93 void drawRect(SkCanvas* canvas, const SkRect& r, NormalMap mapType) { |
94 | 94 |
95 SkRect bitmapBounds = SkRect::MakeIWH(fDiffuse.width(), fDiffuse.height(
)); | 95 SkRect bitmapBounds = SkRect::MakeIWH(fDiffuse.width(), fDiffuse.height(
)); |
96 | 96 |
97 SkMatrix matrix; | 97 SkMatrix matrix; |
98 matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit); | 98 matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit); |
99 | 99 |
100 const SkMatrix& ctm = canvas->getTotalMatrix(); | 100 const SkMatrix& ctm = canvas->getTotalMatrix(); |
101 | 101 |
102 SkPaint paint; | 102 SkPaint paint; |
| 103 sk_sp<SkShader> diffuseShader = SkMakeBitmapShader(fDiffuse, |
| 104 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix, n
ullptr); |
103 sk_sp<SkShader> normalMap = SkMakeBitmapShader(fNormalMaps[mapType], | 105 sk_sp<SkShader> normalMap = SkMakeBitmapShader(fNormalMaps[mapType], |
104 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix, n
ullptr); | 106 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix, n
ullptr); |
105 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(s
td::move(normalMap), | 107 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(s
td::move(normalMap), |
106 c
tm); | 108 c
tm); |
107 paint.setShader(SkLightingShader::Make(fDiffuse, fLights, &matrix, | 109 paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::mo
ve(normalSource), |
108 std::move(normalSource))); | 110 fLights)); |
109 | 111 |
110 canvas->drawRect(r, paint); | 112 canvas->drawRect(r, paint); |
111 } | 113 } |
112 | 114 |
113 void onDraw(SkCanvas* canvas) override { | 115 void onDraw(SkCanvas* canvas) override { |
114 SkMatrix m; | 116 SkMatrix m; |
115 SkRect r; | 117 SkRect r; |
116 | 118 |
117 { | 119 { |
118 r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize))
; | 120 r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize))
; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 174 |
173 sk_sp<SkLights> fLights; | 175 sk_sp<SkLights> fLights; |
174 | 176 |
175 typedef GM INHERITED; | 177 typedef GM INHERITED; |
176 }; | 178 }; |
177 | 179 |
178 ////////////////////////////////////////////////////////////////////////////// | 180 ////////////////////////////////////////////////////////////////////////////// |
179 | 181 |
180 DEF_GM(return new LightingShaderGM;) | 182 DEF_GM(return new LightingShaderGM;) |
181 } | 183 } |
OLD | NEW |