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

Side by Side Diff: samplecode/SampleLighting.cpp

Issue 2026763002: Make use of new SkLights class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix SampleApp slide 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
« no previous file with comments | « gyp/core.gypi ('k') | src/core/SkLight.h » ('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 * 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 #include "DecodeFile.h" 7 #include "DecodeFile.h"
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "Resources.h" 9 #include "Resources.h"
10 10
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkLightingShader.h" 12 #include "SkLightingShader.h"
13 #include "SkPoint3.h" 13 #include "SkPoint3.h"
14 14
15 static const SkLightingShader::Lights* create_lights(SkScalar angle, SkScalar bl ue) { 15 static sk_sp<SkLights> create_lights(SkScalar angle, SkScalar blue) {
16 16
17 const SkVector3 dir = SkVector3::Make(SkScalarSin(angle)*SkScalarSin(SK_Scal arPI*0.25f), 17 const SkVector3 dir = SkVector3::Make(SkScalarSin(angle)*SkScalarSin(SK_Scal arPI*0.25f),
18 SkScalarCos(angle)*SkScalarSin(SK_Scal arPI*0.25f), 18 SkScalarCos(angle)*SkScalarSin(SK_Scal arPI*0.25f),
19 SkScalarCos(SK_ScalarPI*0.25f)); 19 SkScalarCos(SK_ScalarPI*0.25f));
20 20
21 SkLightingShader::Lights::Builder builder; 21 SkLights::Builder builder;
22 22
23 builder.add(SkLight(SkColor3f::Make(1.0f, 1.0f, blue), dir)); 23 builder.add(SkLights::Light(SkColor3f::Make(1.0f, 1.0f, blue), dir));
24 builder.add(SkLight(SkColor3f::Make(0.1f, 0.1f, 0.1f))); 24 builder.add(SkLights::Light(SkColor3f::Make(0.1f, 0.1f, 0.1f)));
25 25
26 return builder.finish(); 26 return builder.finish();
27 } 27 }
28 28
29 //////////////////////////////////////////////////////////////////////////// 29 ////////////////////////////////////////////////////////////////////////////
30 30
31 class LightingView : public SampleView { 31 class LightingView : public SampleView {
32 public: 32 public:
33 SkBitmap fDiffuseBitmap; 33 SkBitmap fDiffuseBitmap;
34 SkBitmap fNormalBitmap; 34 SkBitmap fNormalBitmap;
(...skipping 20 matching lines...) Expand all
55 return this->INHERITED::onQuery(evt); 55 return this->INHERITED::onQuery(evt);
56 } 56 }
57 57
58 void onDrawContent(SkCanvas* canvas) override { 58 void onDrawContent(SkCanvas* canvas) override {
59 fLightAngle += 0.015f; 59 fLightAngle += 0.015f;
60 fColorFactor += 0.01f; 60 fColorFactor += 0.01f;
61 if (fColorFactor > 1.0f) { 61 if (fColorFactor > 1.0f) {
62 fColorFactor = 0.0f; 62 fColorFactor = 0.0f;
63 } 63 }
64 64
65 SkAutoTUnref<const SkLightingShader::Lights> lights(create_lights(fLight Angle, 65 sk_sp<SkLights> lights(create_lights(fLightAngle, fColorFactor));
66 fColor Factor));
67 SkPaint paint; 66 SkPaint paint;
68 paint.setShader(SkLightingShader::Make(fDiffuseBitmap, fNormalBitmap, 67 paint.setShader(SkLightingShader::Make(fDiffuseBitmap, fNormalBitmap,
69 lights, SkVector::Make(1.0f, 0.0f ), 68 std::move(lights), SkVector::Make (1.0f, 0.0f),
70 nullptr, nullptr)); 69 nullptr, nullptr));
71 paint.setColor(SK_ColorBLACK); 70 paint.setColor(SK_ColorBLACK);
72 71
73 SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(), 72 SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(),
74 (SkScalar)fDiffuseBitmap.height()); 73 (SkScalar)fDiffuseBitmap.height());
75 canvas->drawRect(r, paint); 74 canvas->drawRect(r, paint);
76 75
77 // so we're constantly updating 76 // so we're constantly updating
78 this->inval(nullptr); 77 this->inval(nullptr);
79 } 78 }
80 79
81 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride { 80 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride {
82 this->inval(nullptr); 81 this->inval(nullptr);
83 return this->INHERITED::onFindClickHandler(x, y, modi); 82 return this->INHERITED::onFindClickHandler(x, y, modi);
84 } 83 }
85 84
86 private: 85 private:
87 typedef SampleView INHERITED; 86 typedef SampleView INHERITED;
88 }; 87 };
89 88
90 ////////////////////////////////////////////////////////////////////////////// 89 //////////////////////////////////////////////////////////////////////////////
91 90
92 static SkView* MyFactory() { return new LightingView; } 91 static SkView* MyFactory() { return new LightingView; }
93 static SkViewRegister reg(MyFactory); 92 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « gyp/core.gypi ('k') | src/core/SkLight.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698