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

Side by Side Diff: src/core/SkLightingShader.h

Issue 1261433009: Refugee from Dead Machine 11: Add SkCanvas::drawLitAtlas call Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update Created 4 years, 7 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 | « src/core/SkDevice.cpp ('k') | src/core/SkLightingShader.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 8
9 9
10 #ifndef SkLightingShader_DEFINED 10 #ifndef SkLightingShader_DEFINED
11 #define SkLightingShader_DEFINED 11 #define SkLightingShader_DEFINED
12 12
13 #include "SkPoint3.h" 13 #include "SkFlattenable.h"
14 #include "SkLight.h"
14 #include "SkShader.h" 15 #include "SkShader.h"
16 #include "SkTDArray.h"
17
18 class SkBitmap;
19 class SkMatrix;
20 struct SkRSXform;
15 21
16 class SK_API SkLightingShader { 22 class SK_API SkLightingShader {
17 public: 23 public:
18 struct Light { 24 class Lights : public SkRefCnt {
19 SkVector3 fDirection; // direction towards the light (+Z is out of the screen). 25 public:
20 // If degenerate, it will be replaced with (0, 0, 1). 26 class Builder {
21 SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel. 27 public:
28 Builder(const SkLight lights[], int numLights)
29 : fLights(SkNEW_ARGS(Lights, (lights, numLights))) {
30 }
31
32 Builder() : fLights(SkNEW(Lights)) { }
33
34 void add(const SkLight& light) {
35 if (fLights) {
36 *fLights->fLights.push() = light;
37 }
38 }
39
40 const Lights* finish() {
41 return fLights.detach();
42 }
43
44 private:
45 SkAutoTUnref<Lights> fLights;
46 };
47
48 int numLights() const {
49 return fLights.count();
50 }
51
52 const SkLight& light(int index) const {
53 return fLights[index];
54 }
55
56 private:
57 Lights() {}
58 Lights(const SkLight lights[], int numLights) : fLights(lights, numLight s) {}
59
60 SkTDArray<SkLight> fLights;
61
62 typedef SkRefCnt INHERITED;
22 }; 63 };
23 64
24 /** Returns a shader that lights the diffuse and normal maps with a single l ight. 65 /** Returns a shader that lights the diffuse and normal maps with a single l ight.
25 66
26 It returns a shader with a reference count of 1. 67 It returns a shader with a reference count of 1.
27 The caller should decrement the shader's reference count when done with the shader. 68 The caller should decrement the shader's reference count when done with the shader.
28 It is an error for count to be < 2. 69 It is an error for count to be < 2.
29 @param diffuse the diffuse bitmap 70 @param diffuse the diffuse bitmap
30 @param normal the normal map 71 @param normal the normal map
31 @param light the light applied to the normal map 72 @param light the light applied to the normal map
(...skipping 11 matching lines...) Expand all
43 The normal map is currently assumed to be an 8888 image where the normal at a texel 84 The normal map is currently assumed to be an 8888 image where the normal at a texel
44 is retrieved by: 85 is retrieved by:
45 N.x = R-127; 86 N.x = R-127;
46 N.y = G-127; 87 N.y = G-127;
47 N.z = B-127; 88 N.z = B-127;
48 N.normalize(); 89 N.normalize();
49 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is 90 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is
50 (127, 127, 0). 91 (127, 127, 0).
51 */ 92 */
52 static SkShader* Create(const SkBitmap& diffuse, const SkBitmap& normal, 93 static SkShader* Create(const SkBitmap& diffuse, const SkBitmap& normal,
53 const SkLightingShader::Light& light, const SkColor3 f& ambient, 94 const Lights* lights, const SkRSXform& xform,
54 const SkMatrix* localMatrix); 95 const SkMatrix* diffLocalMatrix, const SkMatrix* nor mLocalMatrix);
55 96
56 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() 97 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
57 }; 98 };
58 99
59 #endif 100 #endif
OLDNEW
« no previous file with comments | « src/core/SkDevice.cpp ('k') | src/core/SkLightingShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698