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

Side by Side Diff: samplecode/SampleLighting.cpp

Issue 1829303002: move setshader to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: addressing comments from #8 Created 4 years, 9 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
« no previous file with comments | « samplecode/SampleFilterFuzz.cpp ('k') | src/animator/SkDrawPaint.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "DecodeFile.h" 8 #include "DecodeFile.h"
9 #include "SampleCode.h" 9 #include "SampleCode.h"
10 #include "Resources.h" 10 #include "Resources.h"
(...skipping 13 matching lines...) Expand all
24 builder.add(SkLight(SkColor3f::Make(1.0f, 1.0f, blue), dir)); 24 builder.add(SkLight(SkColor3f::Make(1.0f, 1.0f, blue), dir));
25 builder.add(SkLight(SkColor3f::Make(0.1f, 0.1f, 0.1f))); 25 builder.add(SkLight(SkColor3f::Make(0.1f, 0.1f, 0.1f)));
26 26
27 return builder.finish(); 27 return builder.finish();
28 } 28 }
29 29
30 //////////////////////////////////////////////////////////////////////////// 30 ////////////////////////////////////////////////////////////////////////////
31 31
32 class LightingView : public SampleView { 32 class LightingView : public SampleView {
33 public: 33 public:
34 SkAutoTUnref<SkShader> fShader; 34 SkBitmap fDiffuseBitmap;
35 SkBitmap fDiffuseBitmap; 35 SkBitmap fNormalBitmap;
36 SkBitmap fNormalBitmap; 36 SkScalar fLightAngle;
37 SkScalar fLightAngle; 37 SkScalar fColorFactor;
38 SkScalar fColorFactor;
39 38
40 LightingView() { 39 LightingView() {
41 SkString diffusePath = GetResourcePath("brickwork-texture.jpg"); 40 SkString diffusePath = GetResourcePath("brickwork-texture.jpg");
42 decode_file(diffusePath.c_str(), &fDiffuseBitmap); 41 decode_file(diffusePath.c_str(), &fDiffuseBitmap);
43 SkString normalPath = GetResourcePath("brickwork_normal-map.jpg"); 42 SkString normalPath = GetResourcePath("brickwork_normal-map.jpg");
44 decode_file(normalPath.c_str(), &fNormalBitmap); 43 decode_file(normalPath.c_str(), &fNormalBitmap);
45 44
46 fLightAngle = 0.0f; 45 fLightAngle = 0.0f;
47 fColorFactor = 0.0f; 46 fColorFactor = 0.0f;
48
49 SkAutoTUnref<const SkLightingShader::Lights> lights(create_lights(fLight Angle, 1.0f));
50
51 fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap,
52 lights, SkVector::Make(1.0f, 0.0f ),
53 nullptr, nullptr));
54 } 47 }
55 48
56 virtual ~LightingView() {}
57
58 protected: 49 protected:
59 // overrides from SkEventSink 50 // overrides from SkEventSink
60 bool onQuery(SkEvent* evt) override { 51 bool onQuery(SkEvent* evt) override {
61 if (SampleCode::TitleQ(*evt)) { 52 if (SampleCode::TitleQ(*evt)) {
62 SampleCode::TitleR(evt, "Lighting"); 53 SampleCode::TitleR(evt, "Lighting");
63 return true; 54 return true;
64 } 55 }
65 return this->INHERITED::onQuery(evt); 56 return this->INHERITED::onQuery(evt);
66 } 57 }
67 58
68 void onDrawContent(SkCanvas* canvas) override { 59 void onDrawContent(SkCanvas* canvas) override {
69 fLightAngle += 0.015f; 60 fLightAngle += 0.015f;
70 fColorFactor += 0.01f; 61 fColorFactor += 0.01f;
71 if (fColorFactor > 1.0f) { 62 if (fColorFactor > 1.0f) {
72 fColorFactor = 0.0f; 63 fColorFactor = 0.0f;
73 } 64 }
74 65
75 SkAutoTUnref<const SkLightingShader::Lights> lights(create_lights(fLight Angle, 66 SkAutoTUnref<const SkLightingShader::Lights> lights(create_lights(fLight Angle,
76 fColor Factor)); 67 fColor Factor));
77 68 SkPaint paint;
78 fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap, 69 paint.setShader(SkLightingShader::Make(fDiffuseBitmap, fNormalBitmap,
79 lights, SkVector::Make(1.0f, 0.0f ), 70 lights, SkVector::Make(1.0f, 0.0f ),
80 nullptr, nullptr)); 71 nullptr, nullptr));
81
82 SkPaint paint;
83 paint.setShader(fShader);
84 paint.setColor(SK_ColorBLACK); 72 paint.setColor(SK_ColorBLACK);
85 73
86 SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(), 74 SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(),
87 (SkScalar)fDiffuseBitmap.height()); 75 (SkScalar)fDiffuseBitmap.height());
88 canvas->drawRect(r, paint); 76 canvas->drawRect(r, paint);
89 77
90 // so we're constantly updating 78 // so we're constantly updating
91 this->inval(nullptr); 79 this->inval(nullptr);
92 } 80 }
93 81
94 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride { 82 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride {
95 this->inval(nullptr); 83 this->inval(nullptr);
96 return this->INHERITED::onFindClickHandler(x, y, modi); 84 return this->INHERITED::onFindClickHandler(x, y, modi);
97 } 85 }
98 86
99 private: 87 private:
100 typedef SampleView INHERITED; 88 typedef SampleView INHERITED;
101 }; 89 };
102 90
103 ////////////////////////////////////////////////////////////////////////////// 91 //////////////////////////////////////////////////////////////////////////////
104 92
105 static SkView* MyFactory() { return new LightingView; } 93 static SkView* MyFactory() { return new LightingView; }
106 static SkViewRegister reg(MyFactory); 94 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleFilterFuzz.cpp ('k') | src/animator/SkDrawPaint.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698