Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: samplecode/SampleLitAtlas.cpp

Issue 2064153002: Changed SkLightingShader API to take in a shader as color source (Closed) Base URL: https://skia.googlesource.com/skia@dvonbeck-diffuse-factor-out
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "SkAnimTimer.h" 9 #include "SkAnimTimer.h"
10 #include "SkView.h" 10 #include "SkBitmapProcShader.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkDrawable.h" 12 #include "SkDrawable.h"
13 #include "SkLightingShader.h" 13 #include "SkLightingShader.h"
14 #include "SkLights.h" 14 #include "SkLights.h"
15 #include "SkNormalSource.h" 15 #include "SkNormalSource.h"
16 #include "SkRandom.h" 16 #include "SkRandom.h"
17 #include "SkRSXform.h" 17 #include "SkRSXform.h"
18 #include "SkView.h"
18 19
19 #include "sk_tool_utils.h" 20 #include "sk_tool_utils.h"
20 21
21 class DrawLitAtlasDrawable : public SkDrawable { 22 class DrawLitAtlasDrawable : public SkDrawable {
22 public: 23 public:
23 DrawLitAtlasDrawable(const SkRect& r) 24 DrawLitAtlasDrawable(const SkRect& r)
24 : fBounds(r) 25 : fBounds(r)
25 , fUseColors(false) 26 , fUseColors(false)
26 , fLightDir(SkVector3::Make(1.0f, 0.0f, 0.0f)) { 27 , fLightDir(SkVector3::Make(1.0f, 0.0f, 0.0f)) {
27 fAtlas = MakeAtlas(); 28 fAtlas = MakeAtlas();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 129
129 SkMatrix m; 130 SkMatrix m;
130 m.setRSXform(xforms[i]); 131 m.setRSXform(xforms[i]);
131 132
132 // TODO: correctly pull out the pure rotation 133 // TODO: correctly pull out the pure rotation
133 SkVector invNormRotation = { m[SkMatrix::kMScaleX], m[SkMatrix::kMSk ewY] }; 134 SkVector invNormRotation = { m[SkMatrix::kMScaleX], m[SkMatrix::kMSk ewY] };
134 SkASSERT(SkScalarNearlyEqual(invNormRotation.lengthSqd(), SK_Scalar1 )); 135 SkASSERT(SkScalarNearlyEqual(invNormRotation.lengthSqd(), SK_Scalar1 ));
135 136
136 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeMap(fAtlas, invNormRotation, 137 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeMap(fAtlas, invNormRotation,
137 &normal Mat); 138 &normal Mat);
138 paint.setShader(SkLightingShader::Make(fAtlas, fLights, &diffMat, 139 sk_sp<SkShader> diffuseShader = SkBitmapProcShader::MakeBitmapShader (fAtlas,
139 std::move(normalSource))); 140 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &diffM at);
141 paint.setShader(SkLightingShader::Make(std::move(diffuseShader),
142 std::move(normalSource), fLights));
140 143
141 canvas->save(); 144 canvas->save();
142 canvas->setMatrix(m); 145 canvas->setMatrix(m);
143 canvas->drawRect(r, paint); 146 canvas->drawRect(r, paint);
144 canvas->restore(); 147 canvas->restore();
145 } 148 }
146 #endif 149 #endif
147 150
148 #ifdef SK_DEBUG 151 #ifdef SK_DEBUG
149 { 152 {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 private: 509 private:
507 SkAutoTUnref<DrawLitAtlasDrawable> fDrawable; 510 SkAutoTUnref<DrawLitAtlasDrawable> fDrawable;
508 511
509 typedef SampleView INHERITED; 512 typedef SampleView INHERITED;
510 }; 513 };
511 514
512 ////////////////////////////////////////////////////////////////////////////// 515 //////////////////////////////////////////////////////////////////////////////
513 516
514 static SkView* MyFactory() { return new DrawLitAtlasView; } 517 static SkView* MyFactory() { return new DrawLitAtlasView; }
515 static SkViewRegister reg(MyFactory); 518 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698