summaryrefslogtreecommitdiff
path: root/chromium/skia/ext/skottie_unittest.cc
blob: 1ee873f62dddf183533be0b02b3a6a827ecdd80a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkPixmap.h"
#include "third_party/skia/include/core/SkStream.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/modules/skottie/include/Skottie.h"

TEST(Skottie, Basic) {
  // Just a solid green layer.
  static constexpr char anim_data[] =
      "{"
      "  \"v\" : \"4.12.0\","
      "  \"fr\": 30,"
      "  \"w\" : 400,"
      "  \"h\" : 200,"
      "  \"ip\": 0,"
      "  \"op\": 150,"
      "  \"assets\": [],"

      "  \"layers\": ["
      "    {"
      "      \"ty\": 1,"
      "      \"sw\": 400,"
      "      \"sh\": 200,"
      "      \"sc\": \"#00ff00\","
      "      \"ip\": 0,"
      "      \"op\": 150"
      "    }"
      "  ]"
      "}";

  SkMemoryStream stream(anim_data, strlen(anim_data));
  auto anim = skottie::Animation::Make(&stream);

  ASSERT_TRUE(anim);
  EXPECT_EQ(strcmp(anim->version().c_str(), "4.12.0"), 0);
  EXPECT_EQ(anim->size().width(), 400.0f);
  EXPECT_EQ(anim->size().height(), 200.0f);
  EXPECT_EQ(anim->duration(), 5.0f);

  auto surface = SkSurface::MakeRasterN32Premul(400, 200);
  anim->seek(0);
  anim->render(surface->getCanvas());

  SkPixmap pixmap;
  ASSERT_TRUE(surface->peekPixels(&pixmap));

  for (int i = 0; i < pixmap.width(); ++i) {
    for (int j = 0; j < pixmap.height(); ++j) {
      EXPECT_EQ(pixmap.getColor(i, j), 0xff00ff00);
    }
  }
}