aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2018-07-17 12:30:40 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-17 17:24:50 +0000
commita8cdbd7431b6a27d28db1bc80d7557cedf7e66d0 (patch)
tree3d866605d2236b31da70535f2a4263c55b01acae /tests
parent9e0d7e4072e43495a3907bb2bac7824e8e60c368 (diff)
Restore SkLightingShader and associated classes
This reverts https://skia-review.googlesource.com/c/skia/+/31140 (Remove SkLightingShader and associated classes) and updates the classes to ToT Change-Id: I3b1df1704cca8907aa00f081a7e93339b65ad4fa Reviewed-on: https://skia-review.googlesource.com/141545 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/SerializationTest.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index 5de77cd9fb..10838a9f74 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -13,9 +13,11 @@
#include "SkFontDescriptor.h"
#include "SkImage.h"
#include "SkImageSource.h"
+#include "SkLightingShader.h"
#include "SkMakeUnique.h"
#include "SkMallocPixelRef.h"
#include "SkMatrixPriv.h"
+#include "SkNormalSource.h"
#include "SkOSFile.h"
#include "SkReadBuffer.h"
#include "SkPicturePriv.h"
@@ -558,6 +560,64 @@ DEF_TEST(Serialization, reporter) {
}
TestPictureTypefaceSerialization(reporter);
+
+ // Test SkLightingShader/NormalMapSource serialization
+ {
+ const int kTexSize = 2;
+
+ SkLights::Builder builder;
+
+ builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(1.0f, 1.0f, 1.0f),
+ SkVector3::Make(1.0f, 0.0f, 0.0f)));
+ builder.setAmbientLightColor(SkColor3f::Make(0.2f, 0.2f, 0.2f));
+
+ sk_sp<SkLights> fLights = builder.finish();
+
+ SkBitmap diffuse = sk_tool_utils::create_checkerboard_bitmap(
+ kTexSize, kTexSize,
+ sk_tool_utils::color_to_565(0x0),
+ sk_tool_utils::color_to_565(0xFF804020),
+ 8);
+
+ SkRect bitmapBounds = SkRect::MakeIWH(diffuse.width(), diffuse.height());
+
+ SkMatrix matrix;
+ SkRect r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize));
+ matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit);
+
+ SkMatrix ctm;
+ ctm.setRotate(45);
+ SkBitmap normals;
+ normals.allocN32Pixels(kTexSize, kTexSize);
+
+ sk_tool_utils::create_frustum_normal_map(&normals, SkIRect::MakeWH(kTexSize, kTexSize));
+ sk_sp<SkShader> normalMap = SkShader::MakeBitmapShader(normals, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode, &matrix);
+ sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(std::move(normalMap),
+ ctm);
+ sk_sp<SkShader> diffuseShader = SkShader::MakeBitmapShader(diffuse,
+ SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix);
+
+ sk_sp<SkShader> lightingShader = SkLightingShader::Make(diffuseShader,
+ normalSource,
+ fLights);
+ sk_sp<SkShader>(TestFlattenableSerialization(as_SB(lightingShader.get()), true, reporter));
+
+ lightingShader = SkLightingShader::Make(std::move(diffuseShader),
+ nullptr,
+ fLights);
+ sk_sp<SkShader>(TestFlattenableSerialization(as_SB(lightingShader.get()), true, reporter));
+
+ lightingShader = SkLightingShader::Make(nullptr,
+ std::move(normalSource),
+ fLights);
+ sk_sp<SkShader>(TestFlattenableSerialization(as_SB(lightingShader.get()), true, reporter));
+
+ lightingShader = SkLightingShader::Make(nullptr,
+ nullptr,
+ fLights);
+ sk_sp<SkShader>(TestFlattenableSerialization(as_SB(lightingShader.get()), true, reporter));
+ }
}
///////////////////////////////////////////////////////////////////////////////////////////////////