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