Chromium Code Reviews| Index: src/core/SkLightingShader.cpp |
| diff --git a/src/core/SkLightingShader.cpp b/src/core/SkLightingShader.cpp |
| index 81ee7089466ebbd54f7aa40cc0aeaa25cb80c1cc..b1adf428cf9f98080ffc0de76534a1a36085e29d 100644 |
| --- a/src/core/SkLightingShader.cpp |
| +++ b/src/core/SkLightingShader.cpp |
| @@ -43,31 +43,17 @@ public: |
| /** Create a new lighting shader that uses the provided normal map and |
| lights to light the diffuse bitmap. |
| @param diffuse the diffuse bitmap |
| - @param normal the normal map |
| @param lights the lights applied to the normal map |
| - @param invNormRotation rotation applied to the normal map's normals |
| @param diffLocalM the local matrix for the diffuse coordinates |
| - @param normLocalM the local matrix for the normal coordinates |
| - @param normalSource the normal source for GPU computations |
| + @param normalSource the source of normals for lighting computation |
| */ |
| - SkLightingShaderImpl(const SkBitmap& diffuse, const SkBitmap& normal, |
| + SkLightingShaderImpl(const SkBitmap& diffuse, |
| const sk_sp<SkLights> lights, |
| - const SkVector& invNormRotation, |
| - const SkMatrix* diffLocalM, const SkMatrix* normLocalM, |
| + const SkMatrix* diffLocalM, |
| sk_sp<SkLightingShader::NormalSource> normalSource) |
| : INHERITED(diffLocalM) |
| , fDiffuseMap(diffuse) |
| - , fNormalMap(normal) |
| - , fLights(std::move(lights)) |
| - , fInvNormRotation(invNormRotation) { |
| - |
| - if (normLocalM) { |
| - fNormLocalMatrix = *normLocalM; |
| - } else { |
| - fNormLocalMatrix.reset(); |
| - } |
| - // Pre-cache so future calls to fNormLocalMatrix.getType() are threadsafe. |
| - (void)fNormLocalMatrix.getType(); |
| + , fLights(std::move(lights)) { |
| fNormalSource = std::move(normalSource); |
| } |
| @@ -113,13 +99,8 @@ protected: |
| private: |
| SkBitmap fDiffuseMap; |
| - SkBitmap fNormalMap; |
| - |
| sk_sp<SkLights> fLights; |
| - SkMatrix fNormLocalMatrix; |
| - SkVector fInvNormRotation; |
| - |
| sk_sp<SkLightingShader::NormalSource> fNormalSource; |
| friend class SkLightingShader; |
| @@ -324,8 +305,6 @@ sk_sp<GrFragmentProcessor> SkLightingShaderImpl::asFragmentProcessor( |
| // we assume diffuse and normal maps have same width and height |
| // TODO: support different sizes, will be addressed when diffuse maps are factored out of |
| // SkLightingShader in a future CL |
| - SkASSERT(fDiffuseMap.width() == fNormalMap.width() && |
| - fDiffuseMap.height() == fNormalMap.height()); |
| SkMatrix diffM; |
| if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { |
| @@ -495,26 +474,12 @@ sk_sp<SkFlattenable> SkLightingShaderImpl::CreateProc(SkReadBuffer& buf) { |
| diffLocalM.reset(); |
| } |
| - SkMatrix normLocalM; |
| - bool hasNormLocalM = buf.readBool(); |
| - if (hasNormLocalM) { |
| - buf.readMatrix(&normLocalM); |
| - } else { |
| - normLocalM.reset(); |
| - } |
| - |
| SkBitmap diffuse; |
| if (!buf.readBitmap(&diffuse)) { |
| return nullptr; |
| } |
| diffuse.setImmutable(); |
| - SkBitmap normal; |
| - if (!buf.readBitmap(&normal)) { |
| - return nullptr; |
| - } |
| - normal.setImmutable(); |
| - |
| int numLights = buf.readInt(); |
| SkLights::Builder builder; |
| @@ -540,29 +505,17 @@ sk_sp<SkFlattenable> SkLightingShaderImpl::CreateProc(SkReadBuffer& buf) { |
| sk_sp<SkLights> lights(builder.finish()); |
| - SkVector invNormRotation = {1,0}; |
| - if (!buf.isVersionLT(SkReadBuffer::kLightingShaderWritesInvNormRotation)) { |
| - invNormRotation = buf.readPoint(); |
| - } |
| - |
| sk_sp<SkLightingShader::NormalSource> normalSource( |
| buf.readFlattenable<SkLightingShader::NormalSource>()); |
| - return sk_make_sp<SkLightingShaderImpl>(diffuse, normal, std::move(lights), invNormRotation, |
| - &diffLocalM, &normLocalM, std::move(normalSource)); |
| + return sk_make_sp<SkLightingShaderImpl>(diffuse, std::move(lights), &diffLocalM, |
| + std::move(normalSource)); |
| } |
| void SkLightingShaderImpl::flatten(SkWriteBuffer& buf) const { |
| this->INHERITED::flatten(buf); |
| - bool hasNormLocalM = !fNormLocalMatrix.isIdentity(); |
| - buf.writeBool(hasNormLocalM); |
| - if (hasNormLocalM) { |
| - buf.writeMatrix(fNormLocalMatrix); |
| - } |
| - |
| buf.writeBitmap(fDiffuseMap); |
| - buf.writeBitmap(fNormalMap); |
| buf.writeInt(fLights->numLights()); |
| for (int l = 0; l < fLights->numLights(); ++l) { |
| @@ -576,7 +529,6 @@ void SkLightingShaderImpl::flatten(SkWriteBuffer& buf) const { |
| buf.writeScalarArray(&light.dir().fX, 3); |
| } |
| } |
| - buf.writePoint(fInvNormRotation); |
| buf.writeFlattenable(fNormalSource.get()); |
| } |
| @@ -619,23 +571,14 @@ SkShader::Context* SkLightingShaderImpl::onCreateContext(const ContextRec& rec, |
| /////////////////////////////////////////////////////////////////////////////// |
| -sk_sp<SkShader> SkLightingShader::Make(const SkBitmap& diffuse, const SkBitmap& normal, |
| - sk_sp<SkLights> lights, |
| - const SkVector& invNormRotation, |
| - const SkMatrix* diffLocalM, const SkMatrix* normLocalM) { |
| - if (diffuse.isNull() || SkBitmapProcShader::BitmapIsTooBig(diffuse) || |
| - normal.isNull() || SkBitmapProcShader::BitmapIsTooBig(normal) || |
| - diffuse.width() != normal.width() || |
| - diffuse.height() != normal.height()) { |
| +sk_sp<SkShader> SkLightingShader::Make(const SkBitmap& diffuse, sk_sp<SkLights> lights, |
| + const SkMatrix* diffLocalM, sk_sp<NormalSource> normalSource) { |
|
egdaniel
2016/06/16 13:15:08
We should either check or at minimum assert that n
dvonbeck
2016/06/16 23:21:56
Done. Will return a default implementation of Norm
|
| + if (diffuse.isNull() || SkBitmapProcShader::BitmapIsTooBig(diffuse)) { |
| return nullptr; |
| } |
| - SkASSERT(SkScalarNearlyEqual(invNormRotation.lengthSqd(), SK_Scalar1)); |
| - |
| - sk_sp<SkLightingShader::NormalSource> normalSource = |
| - SkLightingShader::NormalMapSource::Make(normal, invNormRotation, normLocalM); |
| - return sk_make_sp<SkLightingShaderImpl>(diffuse, normal, std::move(lights), |
| - invNormRotation, diffLocalM, normLocalM, std::move(normalSource)); |
| + return sk_make_sp<SkLightingShaderImpl>(diffuse, std::move(lights), diffLocalM, |
| + std::move(normalSource)); |
| } |
| /////////////////////////////////////////////////////////////////////////////// |