Skip to content

Commit

Permalink
Enable building Skia's Lottie engine
Browse files Browse the repository at this point in the history
Making Skottie available for future CrOS UI work.

Change-Id: I41946a4f0d09099e15bf4d08a64bb566080ff393
Reviewed-on: https://chromium-review.googlesource.com/1160772
Reviewed-by: Mike Reed <reed@chromium.org>
Reviewed-by: Ben Wagner <bungeman@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580374}
  • Loading branch information
fmalita authored and Commit Bot committed Aug 2, 2018
1 parent a036163 commit 9785633
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
20 changes: 19 additions & 1 deletion skia/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if (current_cpu == "mipsel" || current_cpu == "mips64el") {

skia_support_gpu = !is_ios
skia_support_pdf = !is_ios && enable_basic_printing
skia_support_skottie = true

declare_args() {
skia_whitelist_serialized_typefaces = false
Expand Down Expand Up @@ -112,6 +113,10 @@ config("skia_config") {
if (skia_whitelist_serialized_typefaces) {
defines += [ "SK_WHITELIST_SERIALIZED_TYPEFACES" ]
}

if (skia_support_skottie) {
include_dirs += [ "//third_party/skia/modules/skottie/include" ]
}
}

# Internal-facing config for Skia library code.
Expand Down Expand Up @@ -226,6 +231,10 @@ config("skia_library_config") {
"/wd4800", # forcing value to bool 'true/false'(assigning int to bool).
]
}

if (skia_support_skottie) {
include_dirs += [ "//third_party/skia/modules/sksg/include" ]
}
}

import("//third_party/skia/third_party/skcms/skcms.gni")
Expand Down Expand Up @@ -393,7 +402,6 @@ component("skia") {
"//third_party/skia/src/utils/SkCamera.cpp",
"//third_party/skia/src/utils/SkFrontBufferedStream.cpp",
"//third_party/skia/src/utils/SkInterpolator.cpp",
"//third_party/skia/src/utils/SkOSPath.cpp",
"//third_party/skia/src/utils/SkParsePath.cpp",
]

Expand Down Expand Up @@ -564,6 +572,12 @@ component("skia") {
sources += [ "//third_party/skia/src/pdf/SkDocument_PDF_None.cpp" ]
}

if (skia_support_skottie) {
import("//third_party/skia/modules/skottie/skottie.gni")
import("//third_party/skia/modules/sksg/sksg.gni")
sources += skia_skottie_sources + skia_skottie_public + skia_sksg_sources
}

if (!is_debug) {
configs -= [ "//build/config/compiler:default_optimization" ]
configs += [ "//build/config/compiler:optimize_max" ]
Expand Down Expand Up @@ -819,6 +833,10 @@ test("skia_unittests") {
"//third_party/test_fonts",
]
}

if (skia_support_skottie) {
sources += [ "ext/skottie_unittest.cc" ]
}
}

if (!is_ios) {
Expand Down
56 changes: 56 additions & 0 deletions skia/ext/skottie_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
}
}

0 comments on commit 9785633

Please sign in to comment.