aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/lightingshader.cpp6
-rwxr-xr-xsamplecode/SampleLighting.cpp6
-rw-r--r--samplecode/SampleLitAtlas.cpp6
-rw-r--r--src/core/SkLightingShader.cpp18
-rw-r--r--src/core/SkLightingShader.h21
-rw-r--r--tests/SerializationTest.cpp7
6 files changed, 29 insertions, 35 deletions
diff --git a/gm/lightingshader.cpp b/gm/lightingshader.cpp
index 3b1c224f2b..2cf4a953d8 100644
--- a/gm/lightingshader.cpp
+++ b/gm/lightingshader.cpp
@@ -100,12 +100,14 @@ protected:
const SkMatrix& ctm = canvas->getTotalMatrix();
SkPaint paint;
+ sk_sp<SkShader> diffuseShader = SkMakeBitmapShader(fDiffuse,
+ SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix, nullptr);
sk_sp<SkShader> normalMap = SkMakeBitmapShader(fNormalMaps[mapType],
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix, nullptr);
sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(std::move(normalMap),
ctm);
- paint.setShader(SkLightingShader::Make(fDiffuse, fLights, &matrix,
- std::move(normalSource)));
+ paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::move(normalSource),
+ fLights));
canvas->drawRect(r, paint);
}
diff --git a/samplecode/SampleLighting.cpp b/samplecode/SampleLighting.cpp
index 5949f4961b..c191a6c749 100755
--- a/samplecode/SampleLighting.cpp
+++ b/samplecode/SampleLighting.cpp
@@ -70,8 +70,10 @@ protected:
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr, nullptr);
sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(
std::move(normalMap), SkMatrix::I());
- paint.setShader(SkLightingShader::Make(fDiffuseBitmap, std::move(lights), nullptr,
- std::move(normalSource)));
+ sk_sp<SkShader> diffuseShader = SkBitmapProcShader::MakeBitmapShader(fDiffuseBitmap,
+ SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr);
+ paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::move(normalSource),
+ std::move(lights)));
paint.setColor(SK_ColorBLACK);
SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(),
diff --git a/samplecode/SampleLitAtlas.cpp b/samplecode/SampleLitAtlas.cpp
index ba42ed8761..f1882b7890 100644
--- a/samplecode/SampleLitAtlas.cpp
+++ b/samplecode/SampleLitAtlas.cpp
@@ -134,8 +134,10 @@ protected:
SkShader::kClamp_TileMode, &normalMat, nullptr);
sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(
std::move(normalMap), m);
- paint.setShader(SkLightingShader::Make(fAtlas, fLights, &diffMat,
- std::move(normalSource)));
+ sk_sp<SkShader> diffuseShader = SkBitmapProcShader::MakeBitmapShader(fAtlas,
+ SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &diffMat);
+ paint.setShader(SkLightingShader::Make(std::move(diffuseShader),
+ std::move(normalSource), fLights));
canvas->save();
canvas->setMatrix(m);
diff --git a/src/core/SkLightingShader.cpp b/src/core/SkLightingShader.cpp
index 84ec64cc06..02f14b34dd 100644
--- a/src/core/SkLightingShader.cpp
+++ b/src/core/SkLightingShader.cpp
@@ -488,23 +488,15 @@ SkShader::Context* SkLightingShaderImpl::onCreateContext(const ContextRec& rec,
///////////////////////////////////////////////////////////////////////////////
-sk_sp<SkShader> SkLightingShader::Make(const SkBitmap& diffuse,
- sk_sp<SkLights> lights,
- const SkMatrix* diffLocalM,
- sk_sp<SkNormalSource> normalSource) {
- if (diffuse.isNull() || SkBitmapProcShader::BitmapIsTooBig(diffuse)) {
- return nullptr;
- }
-
- if (!normalSource) {
+sk_sp<SkShader> SkLightingShader::Make(sk_sp<SkShader> diffuseShader,
+ sk_sp<SkNormalSource> normalSource,
+ sk_sp<SkLights> lights) {
+ if (!diffuseShader || !normalSource) {
+ // TODO: Use paint's color in absence of a diffuseShader
// TODO: Use a default implementation of normalSource instead
return nullptr;
}
- // TODO: support other tile modes
- sk_sp<SkShader> diffuseShader = SkBitmapProcShader::MakeBitmapShader(diffuse,
- SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, diffLocalM);
-
return sk_make_sp<SkLightingShaderImpl>(std::move(diffuseShader), std::move(normalSource),
std::move(lights));
}
diff --git a/src/core/SkLightingShader.h b/src/core/SkLightingShader.h
index f10382368a..bb642615a5 100644
--- a/src/core/SkLightingShader.h
+++ b/src/core/SkLightingShader.h
@@ -17,29 +17,22 @@ class SkNormalSource;
class SK_API SkLightingShader {
public:
- /** Returns a shader that lights the diffuse map using the normals and a set of lights.
+ /** Returns a shader that lights the shape, colored by the diffuseShader, using the
+ normals from normalSource, with the set of lights provided.
It returns a shader with a reference count of 1.
The caller should decrement the shader's reference count when done with the shader.
It is an error for count to be < 2.
- @param diffuse the diffuse bitmap
- @param lights the lights applied to the normal map
- @param diffLocalMatrix the local matrix for the diffuse map (transform from
- texture coordinates to shape source coordinates). nullptr is
- interpreted as an identity matrix.
- @param normalSource the source for the normals
-
- nullptr will be returned if:
- 'diffuse' is empty
- 'diffuse' is too big (> 65535 on any side)
+ @param diffuseShader the shader that provides the colors
+ @param normalSource the source for the shape's normals
+ @param lights the lights applied to the normals
The lighting equation is currently:
result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientColor
*/
- static sk_sp<SkShader> Make(const SkBitmap& diffuse, sk_sp<SkLights> lights,
- const SkMatrix* diffLocalMatrix,
- sk_sp<SkNormalSource> normalSource);
+ static sk_sp<SkShader> Make(sk_sp<SkShader> diffuseShader, sk_sp<SkNormalSource> normalSource,
+ sk_sp<SkLights> lights);
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
};
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index 1e96eefd54..88f88fc2ac 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -585,8 +585,11 @@ DEF_TEST(Serialization, reporter) {
SkShader::kClamp_TileMode, &matrix, nullptr);
sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(std::move(normalMap),
ctm);
- sk_sp<SkShader> lightingShader = SkLightingShader::Make(diffuse, fLights, &matrix,
- std::move(normalSource));
+ sk_sp<SkShader> diffuseShader = SkMakeBitmapShader(diffuse, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode, &matrix, nullptr);
+ sk_sp<SkShader> lightingShader = SkLightingShader::Make(std::move(diffuseShader),
+ std::move(normalSource),
+ fLights);
SkAutoTUnref<SkShader>(TestFlattenableSerialization(lightingShader.get(), true, reporter));
// TODO test equality?