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

Side by Side Diff: samplecode/SampleLighting.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 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 "SkBitmapProcShader.h"
11 #include "SkCanvas.h" 12 #include "SkCanvas.h"
12 #include "SkLightingShader.h" 13 #include "SkLightingShader.h"
13 #include "SkNormalSource.h" 14 #include "SkNormalSource.h"
14 #include "SkPoint3.h" 15 #include "SkPoint3.h"
15 16
16 static sk_sp<SkLights> create_lights(SkScalar angle, SkScalar blue) { 17 static sk_sp<SkLights> create_lights(SkScalar angle, SkScalar blue) {
17 18
18 const SkVector3 dir = SkVector3::Make(SkScalarSin(angle)*SkScalarSin(SK_Scal arPI*0.25f), 19 const SkVector3 dir = SkVector3::Make(SkScalarSin(angle)*SkScalarSin(SK_Scal arPI*0.25f),
19 SkScalarCos(angle)*SkScalarSin(SK_Scal arPI*0.25f), 20 SkScalarCos(angle)*SkScalarSin(SK_Scal arPI*0.25f),
20 SkScalarCos(SK_ScalarPI*0.25f)); 21 SkScalarCos(SK_ScalarPI*0.25f));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 59
59 void onDrawContent(SkCanvas* canvas) override { 60 void onDrawContent(SkCanvas* canvas) override {
60 fLightAngle += 0.015f; 61 fLightAngle += 0.015f;
61 fColorFactor += 0.01f; 62 fColorFactor += 0.01f;
62 if (fColorFactor > 1.0f) { 63 if (fColorFactor > 1.0f) {
63 fColorFactor = 0.0f; 64 fColorFactor = 0.0f;
64 } 65 }
65 66
66 sk_sp<SkLights> lights(create_lights(fLightAngle, fColorFactor)); 67 sk_sp<SkLights> lights(create_lights(fLightAngle, fColorFactor));
67 SkPaint paint; 68 SkPaint paint;
69 sk_sp<SkShader> diffuseShader = SkBitmapProcShader::MakeBitmapShader(fDi ffuseBitmap,
70 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr);
68 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeMap(fNormalBitm ap, 71 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeMap(fNormalBitm ap,
69 SkVector::M ake(1.0f, 0.0f), 72 SkVector::M ake(1.0f, 0.0f),
70 nullptr); 73 nullptr);
71 paint.setShader(SkLightingShader::Make(fDiffuseBitmap, std::move(lights) , nullptr, 74 paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::mo ve(normalSource),
72 std::move(normalSource))); 75 std::move(lights)));
73 paint.setColor(SK_ColorBLACK); 76 paint.setColor(SK_ColorBLACK);
74 77
75 SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(), 78 SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(),
76 (SkScalar)fDiffuseBitmap.height()); 79 (SkScalar)fDiffuseBitmap.height());
77 canvas->drawRect(r, paint); 80 canvas->drawRect(r, paint);
78 81
79 // so we're constantly updating 82 // so we're constantly updating
80 this->inval(nullptr); 83 this->inval(nullptr);
81 } 84 }
82 85
83 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride { 86 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride {
84 this->inval(nullptr); 87 this->inval(nullptr);
85 return this->INHERITED::onFindClickHandler(x, y, modi); 88 return this->INHERITED::onFindClickHandler(x, y, modi);
86 } 89 }
87 90
88 private: 91 private:
89 typedef SampleView INHERITED; 92 typedef SampleView INHERITED;
90 }; 93 };
91 94
92 ////////////////////////////////////////////////////////////////////////////// 95 //////////////////////////////////////////////////////////////////////////////
93 96
94 static SkView* MyFactory() { return new LightingView; } 97 static SkView* MyFactory() { return new LightingView; }
95 static SkViewRegister reg(MyFactory); 98 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698