Chromium Code Reviews| Index: include/core/SkLights.h |
| diff --git a/include/core/SkLights.h b/include/core/SkLights.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4237bdebfb2fc7009b9539b5b16535e9dade5433 |
| --- /dev/null |
| +++ b/include/core/SkLights.h |
| @@ -0,0 +1,90 @@ |
| + |
| +/* |
| + * Copyright 2015 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#ifndef SkLights_DEFINED |
| +#define SkLights_DEFINED |
| + |
| +#include "SkPoint3.h" |
| +#include "SkRefCnt.h" |
| +#include "SkTDArray.h" |
| + |
| +class SK_API SkLights : public SkRefCnt { |
| +public: |
| + class Light { |
| + public: |
| + enum LightType { |
| + kAmbient_LightType, // only 'fColor' is used |
| + kInfinite_LightType |
|
bsalomon
2015/08/05 14:58:38
directional?
robertphillips
2015/08/05 15:40:24
Done.
|
| + }; |
| + |
| + Light(const SkColor3f& color) |
| + : fType(kAmbient_LightType) |
| + , fColor(color) { |
| + fDirection.set(0.0f, 0.0f, 1.0f); |
| + } |
| + |
| + Light(const SkColor3f& color, const SkVector3& dir) |
| + : fType(kInfinite_LightType) |
| + , fColor(color) |
| + , fDirection(dir) { |
| + if (!fDirection.normalize()) { |
| + fDirection.set(0.0f, 0.0f, 1.0f); |
| + } |
| + } |
| + |
| + LightType type() const { return fType; } |
| + const SkColor3f& color() const { return fColor; } |
| + const SkVector3& dir() const { |
| + SkASSERT(kAmbient_LightType != fType); |
| + return fDirection; |
| + } |
| + |
| + private: |
| + LightType fType; |
| + SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel. |
| + SkVector3 fDirection; // direction towards the light (+Z is out of the screen). |
| + // If degenerate, it will be replaced with (0, 0, 1). |
| + }; |
| + |
| + class Editor { |
|
bsalomon
2015/08/05 14:58:38
Maybe just have a builder and immutable light set?
robertphillips
2015/08/05 15:40:24
Done.
|
| + public: |
| + Editor(SkAutoTUnref<SkLights>* lights) { |
| + if (!(*lights)->unique()) { |
| + SkLights* copy = SkNEW(SkLights); |
| + copy->copy(**lights); |
| + lights->reset(copy); |
| + } |
| + fLights = *lights; |
| + } |
| + |
| + void add(const Light& light) { |
| + *fLights->fLights.push() = light; |
| + } |
| + |
| + private: |
| + SkLights* fLights; |
| + }; |
| + |
| + int numLights() const { |
| + return fLights.count(); |
| + } |
| + |
| + const Light& light(int index) const { |
| + return fLights[index]; |
| + } |
| + |
| +private: |
| + void copy(const SkLights& src) { |
| + fLights.setCount(src.numLights()); |
| + src.fLights.copy(fLights.begin()); |
| + } |
| + |
| + SkTDArray<Light> fLights; |
| +}; |
| + |
| +#endif |