Add rive to third_party

Add rive slide to Viewer

Change-Id: Id25a7ac2a65e816544159ff4b3f582249f9ba0ce
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/541742
Auto-Submit: Mike Reed <mike@reedtribe.org>
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
This commit is contained in:
Michael Reed 2022-05-19 20:08:01 -04:00 committed by SkCQ
parent b2a8a7e3e8
commit 14aa53bf38
8 changed files with 454 additions and 0 deletions

View File

@ -2819,6 +2819,8 @@ if (skia_enable_tools) {
"tools/viewer/MSKPSlide.h",
"tools/viewer/ParticlesSlide.cpp",
"tools/viewer/ParticlesSlide.h",
"tools/viewer/RiveSlide.cpp",
"tools/viewer/RiveSlide.h",
"tools/viewer/SKPSlide.cpp",
"tools/viewer/SKPSlide.h",
"tools/viewer/SampleSlide.cpp",
@ -2862,6 +2864,7 @@ if (skia_enable_tools) {
"modules/sksg:samples",
"modules/svg",
"//third_party/imgui",
"//third_party/rive",
]
if (skia_use_vulkan) {
deps += [

1
DEPS
View File

@ -36,6 +36,7 @@ deps = {
"third_party/externals/oboe" : "https://chromium.googlesource.com/external/github.com/google/oboe.git@b02a12d1dd821118763debec6b83d00a8a0ee419",
"third_party/externals/opengl-registry" : "https://skia.googlesource.com/external/github.com/KhronosGroup/OpenGL-Registry@14b80ebeab022b2c78f84a573f01028c96075553",
"third_party/externals/piex" : "https://android.googlesource.com/platform/external/piex.git@bb217acdca1cc0c16b704669dd6f91a1b509c406",
"third_party/externals/rive" : "https://skia.googlesource.com/external/github.com/rive-app/rive-cpp.git@2e80e5803390f16e5047c8e15ab78f7a1d846856",
"third_party/externals/sfntly" : "https://chromium.googlesource.com/external/github.com/googlei18n/sfntly.git@b55ff303ea2f9e26702b514cf6a3196a2e3e2974",
"third_party/externals/swiftshader" : "https://swiftshader.googlesource.com/SwiftShader@73679602bc0be54c3fba1caaf2141b05f19aa468",
"third_party/externals/vulkanmemoryallocator" : "https://chromium.googlesource.com/external/github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator@7de5cc00de50e71a3aab22dea52fbb7ff4efceb6",

232
third_party/rive/BUILD.gn vendored Normal file
View File

@ -0,0 +1,232 @@
# Copyright 2022 Rive Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("../third_party.gni")
third_party("rive") {
public_include_dirs = [
"../externals/rive/include",
"../externals/rive/skia/renderer/include",
]
include_dirs = [
"../externals/rive/include",
"../..",
]
sources = [
"../externals/rive/skia/renderer/src/skia_factory.cpp",
"../externals/rive/src/animation/animation_state.cpp",
"../externals/rive/src/animation/animation_state_instance.cpp",
"../externals/rive/src/animation/blend_animation.cpp",
"../externals/rive/src/animation/blend_animation_1d.cpp",
"../externals/rive/src/animation/blend_animation_direct.cpp",
"../externals/rive/src/animation/blend_state.cpp",
"../externals/rive/src/animation/blend_state_1d.cpp",
"../externals/rive/src/animation/blend_state_1d_instance.cpp",
"../externals/rive/src/animation/blend_state_direct.cpp",
"../externals/rive/src/animation/blend_state_direct_instance.cpp",
"../externals/rive/src/animation/blend_state_transition.cpp",
"../externals/rive/src/animation/cubic_interpolator.cpp",
"../externals/rive/src/animation/event_bool_change.cpp",
"../externals/rive/src/animation/event_input_change.cpp",
"../externals/rive/src/animation/event_number_change.cpp",
"../externals/rive/src/animation/event_trigger_change.cpp",
"../externals/rive/src/animation/keyed_object.cpp",
"../externals/rive/src/animation/keyed_property.cpp",
"../externals/rive/src/animation/keyframe.cpp",
"../externals/rive/src/animation/keyframe_bool.cpp",
"../externals/rive/src/animation/keyframe_color.cpp",
"../externals/rive/src/animation/keyframe_double.cpp",
"../externals/rive/src/animation/keyframe_id.cpp",
"../externals/rive/src/animation/layer_state.cpp",
"../externals/rive/src/animation/linear_animation.cpp",
"../externals/rive/src/animation/linear_animation_instance.cpp",
"../externals/rive/src/animation/nested_animation.cpp",
"../externals/rive/src/animation/nested_linear_animation.cpp",
"../externals/rive/src/animation/nested_remap_animation.cpp",
"../externals/rive/src/animation/nested_simple_animation.cpp",
"../externals/rive/src/animation/nested_state_machine.cpp",
"../externals/rive/src/animation/state_instance.cpp",
"../externals/rive/src/animation/state_machine.cpp",
"../externals/rive/src/animation/state_machine_event.cpp",
"../externals/rive/src/animation/state_machine_input.cpp",
"../externals/rive/src/animation/state_machine_input_instance.cpp",
"../externals/rive/src/animation/state_machine_instance.cpp",
"../externals/rive/src/animation/state_machine_layer.cpp",
"../externals/rive/src/animation/state_transition.cpp",
"../externals/rive/src/animation/system_state_instance.cpp",
"../externals/rive/src/animation/transition_bool_condition.cpp",
"../externals/rive/src/animation/transition_condition.cpp",
"../externals/rive/src/animation/transition_number_condition.cpp",
"../externals/rive/src/animation/transition_trigger_condition.cpp",
"../externals/rive/src/artboard.cpp",
"../externals/rive/src/assets/file_asset.cpp",
"../externals/rive/src/assets/file_asset_contents.cpp",
"../externals/rive/src/assets/image_asset.cpp",
"../externals/rive/src/bones/bone.cpp",
"../externals/rive/src/bones/root_bone.cpp",
"../externals/rive/src/bones/skin.cpp",
"../externals/rive/src/bones/skinnable.cpp",
"../externals/rive/src/bones/tendon.cpp",
"../externals/rive/src/bones/weight.cpp",
"../externals/rive/src/component.cpp",
"../externals/rive/src/constraints/constraint.cpp",
"../externals/rive/src/constraints/distance_constraint.cpp",
"../externals/rive/src/constraints/ik_constraint.cpp",
"../externals/rive/src/constraints/rotation_constraint.cpp",
"../externals/rive/src/constraints/scale_constraint.cpp",
"../externals/rive/src/constraints/targeted_constraint.cpp",
"../externals/rive/src/constraints/transform_constraint.cpp",
"../externals/rive/src/constraints/translation_constraint.cpp",
"../externals/rive/src/core/binary_reader.cpp",
"../externals/rive/src/core/field_types/core_bool_type.cpp",
"../externals/rive/src/core/field_types/core_bytes_type.cpp",
"../externals/rive/src/core/field_types/core_color_type.cpp",
"../externals/rive/src/core/field_types/core_double_type.cpp",
"../externals/rive/src/core/field_types/core_string_type.cpp",
"../externals/rive/src/core/field_types/core_uint_type.cpp",
"../externals/rive/src/dependency_sorter.cpp",
"../externals/rive/src/draw_rules.cpp",
"../externals/rive/src/draw_target.cpp",
"../externals/rive/src/drawable.cpp",
"../externals/rive/src/file.cpp",
"../externals/rive/src/generated/animation/animation_base.cpp",
"../externals/rive/src/generated/animation/animation_state_base.cpp",
"../externals/rive/src/generated/animation/any_state_base.cpp",
"../externals/rive/src/generated/animation/blend_animation_1d_base.cpp",
"../externals/rive/src/generated/animation/blend_animation_direct_base.cpp",
"../externals/rive/src/generated/animation/blend_state_1d_base.cpp",
"../externals/rive/src/generated/animation/blend_state_direct_base.cpp",
"../externals/rive/src/generated/animation/blend_state_transition_base.cpp",
"../externals/rive/src/generated/animation/cubic_interpolator_base.cpp",
"../externals/rive/src/generated/animation/entry_state_base.cpp",
"../externals/rive/src/generated/animation/event_bool_change_base.cpp",
"../externals/rive/src/generated/animation/event_number_change_base.cpp",
"../externals/rive/src/generated/animation/event_trigger_change_base.cpp",
"../externals/rive/src/generated/animation/exit_state_base.cpp",
"../externals/rive/src/generated/animation/keyed_object_base.cpp",
"../externals/rive/src/generated/animation/keyed_property_base.cpp",
"../externals/rive/src/generated/animation/keyframe_bool_base.cpp",
"../externals/rive/src/generated/animation/keyframe_color_base.cpp",
"../externals/rive/src/generated/animation/keyframe_double_base.cpp",
"../externals/rive/src/generated/animation/keyframe_id_base.cpp",
"../externals/rive/src/generated/animation/linear_animation_base.cpp",
"../externals/rive/src/generated/animation/nested_remap_animation_base.cpp",
"../externals/rive/src/generated/animation/nested_simple_animation_base.cpp",
"../externals/rive/src/generated/animation/nested_state_machine_base.cpp",
"../externals/rive/src/generated/animation/state_machine_base.cpp",
"../externals/rive/src/generated/animation/state_machine_bool_base.cpp",
"../externals/rive/src/generated/animation/state_machine_event_base.cpp",
"../externals/rive/src/generated/animation/state_machine_layer_base.cpp",
"../externals/rive/src/generated/animation/state_machine_number_base.cpp",
"../externals/rive/src/generated/animation/state_machine_trigger_base.cpp",
"../externals/rive/src/generated/animation/state_transition_base.cpp",
"../externals/rive/src/generated/animation/transition_bool_condition_base.cpp",
"../externals/rive/src/generated/animation/transition_number_condition_base.cpp",
"../externals/rive/src/generated/animation/transition_trigger_condition_base.cpp",
"../externals/rive/src/generated/artboard_base.cpp",
"../externals/rive/src/generated/assets/file_asset_contents_base.cpp",
"../externals/rive/src/generated/assets/folder_base.cpp",
"../externals/rive/src/generated/assets/image_asset_base.cpp",
"../externals/rive/src/generated/backboard_base.cpp",
"../externals/rive/src/generated/bones/bone_base.cpp",
"../externals/rive/src/generated/bones/cubic_weight_base.cpp",
"../externals/rive/src/generated/bones/root_bone_base.cpp",
"../externals/rive/src/generated/bones/skin_base.cpp",
"../externals/rive/src/generated/bones/tendon_base.cpp",
"../externals/rive/src/generated/bones/weight_base.cpp",
"../externals/rive/src/generated/constraints/distance_constraint_base.cpp",
"../externals/rive/src/generated/constraints/ik_constraint_base.cpp",
"../externals/rive/src/generated/constraints/rotation_constraint_base.cpp",
"../externals/rive/src/generated/constraints/scale_constraint_base.cpp",
"../externals/rive/src/generated/constraints/transform_constraint_base.cpp",
"../externals/rive/src/generated/constraints/translation_constraint_base.cpp",
"../externals/rive/src/generated/draw_rules_base.cpp",
"../externals/rive/src/generated/draw_target_base.cpp",
"../externals/rive/src/generated/nested_artboard_base.cpp",
"../externals/rive/src/generated/node_base.cpp",
"../externals/rive/src/generated/shapes/clipping_shape_base.cpp",
"../externals/rive/src/generated/shapes/contour_mesh_vertex_base.cpp",
"../externals/rive/src/generated/shapes/cubic_asymmetric_vertex_base.cpp",
"../externals/rive/src/generated/shapes/cubic_detached_vertex_base.cpp",
"../externals/rive/src/generated/shapes/cubic_mirrored_vertex_base.cpp",
"../externals/rive/src/generated/shapes/ellipse_base.cpp",
"../externals/rive/src/generated/shapes/image_base.cpp",
"../externals/rive/src/generated/shapes/mesh_base.cpp",
"../externals/rive/src/generated/shapes/mesh_vertex_base.cpp",
"../externals/rive/src/generated/shapes/paint/fill_base.cpp",
"../externals/rive/src/generated/shapes/paint/gradient_stop_base.cpp",
"../externals/rive/src/generated/shapes/paint/linear_gradient_base.cpp",
"../externals/rive/src/generated/shapes/paint/radial_gradient_base.cpp",
"../externals/rive/src/generated/shapes/paint/solid_color_base.cpp",
"../externals/rive/src/generated/shapes/paint/stroke_base.cpp",
"../externals/rive/src/generated/shapes/paint/trim_path_base.cpp",
"../externals/rive/src/generated/shapes/points_path_base.cpp",
"../externals/rive/src/generated/shapes/polygon_base.cpp",
"../externals/rive/src/generated/shapes/rectangle_base.cpp",
"../externals/rive/src/generated/shapes/shape_base.cpp",
"../externals/rive/src/generated/shapes/star_base.cpp",
"../externals/rive/src/generated/shapes/straight_vertex_base.cpp",
"../externals/rive/src/generated/shapes/triangle_base.cpp",
"../externals/rive/src/hittest_command_path.cpp",
"../externals/rive/src/importers/artboard_importer.cpp",
"../externals/rive/src/importers/backboard_importer.cpp",
"../externals/rive/src/importers/file_asset_importer.cpp",
"../externals/rive/src/importers/keyed_object_importer.cpp",
"../externals/rive/src/importers/keyed_property_importer.cpp",
"../externals/rive/src/importers/layer_state_importer.cpp",
"../externals/rive/src/importers/linear_animation_importer.cpp",
"../externals/rive/src/importers/state_machine_event_importer.cpp",
"../externals/rive/src/importers/state_machine_importer.cpp",
"../externals/rive/src/importers/state_machine_layer_importer.cpp",
"../externals/rive/src/importers/state_transition_importer.cpp",
"../externals/rive/src/layout.cpp",
"../externals/rive/src/math/aabb.cpp",
"../externals/rive/src/math/hit_test.cpp",
"../externals/rive/src/math/mat2d.cpp",
"../externals/rive/src/math/raw_path.cpp",
"../externals/rive/src/math/vec2d.cpp",
"../externals/rive/src/nested_artboard.cpp",
"../externals/rive/src/node.cpp",
"../externals/rive/src/renderer.cpp",
"../externals/rive/src/scene.cpp",
"../externals/rive/src/shapes/clipping_shape.cpp",
"../externals/rive/src/shapes/cubic_asymmetric_vertex.cpp",
"../externals/rive/src/shapes/cubic_detached_vertex.cpp",
"../externals/rive/src/shapes/cubic_mirrored_vertex.cpp",
"../externals/rive/src/shapes/cubic_vertex.cpp",
"../externals/rive/src/shapes/ellipse.cpp",
"../externals/rive/src/shapes/image.cpp",
"../externals/rive/src/shapes/mesh.cpp",
"../externals/rive/src/shapes/mesh_vertex.cpp",
"../externals/rive/src/shapes/metrics_path.cpp",
"../externals/rive/src/shapes/paint/color.cpp",
"../externals/rive/src/shapes/paint/fill.cpp",
"../externals/rive/src/shapes/paint/gradient_stop.cpp",
"../externals/rive/src/shapes/paint/linear_gradient.cpp",
"../externals/rive/src/shapes/paint/radial_gradient.cpp",
"../externals/rive/src/shapes/paint/shape_paint.cpp",
"../externals/rive/src/shapes/paint/shape_paint_mutator.cpp",
"../externals/rive/src/shapes/paint/solid_color.cpp",
"../externals/rive/src/shapes/paint/stroke.cpp",
"../externals/rive/src/shapes/paint/trim_path.cpp",
"../externals/rive/src/shapes/parametric_path.cpp",
"../externals/rive/src/shapes/path.cpp",
"../externals/rive/src/shapes/path_composer.cpp",
"../externals/rive/src/shapes/path_vertex.cpp",
"../externals/rive/src/shapes/points_path.cpp",
"../externals/rive/src/shapes/polygon.cpp",
"../externals/rive/src/shapes/rectangle.cpp",
"../externals/rive/src/shapes/shape.cpp",
"../externals/rive/src/shapes/shape_paint_container.cpp",
"../externals/rive/src/shapes/star.cpp",
"../externals/rive/src/shapes/straight_vertex.cpp",
"../externals/rive/src/shapes/triangle.cpp",
"../externals/rive/src/shapes/vertex.cpp",
"../externals/rive/src/transform_component.cpp",
"../externals/rive/src/world_transform_component.cpp",
]
}

21
third_party/rive/LICENSE vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Rive
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -422,6 +422,7 @@ generated_cc_atom(
":ImageSlide_hdr",
":MSKPSlide_hdr",
":ParticlesSlide_hdr",
":RiveSlide_hdr",
":SKPSlide_hdr",
":SampleSlide_hdr",
":SkSLDebuggerSlide_hdr",
@ -498,3 +499,26 @@ generated_cc_atom(
"//include/core:SkStream_hdr",
],
)
generated_cc_atom(
name = "RiveSlide_hdr",
hdrs = ["RiveSlide.h"],
visibility = ["//:__subpackages__"],
deps = [
":Slide_hdr",
"//include/core:SkMatrix_hdr",
"//include/core:SkRect_hdr",
],
)
generated_cc_atom(
name = "RiveSlide_src",
srcs = ["RiveSlide.cpp"],
visibility = ["//:__subpackages__"],
deps = [
":RiveSlide_hdr",
"//include/core:SkCanvas_hdr",
"//include/core:SkTime_hdr",
"//tools/timer:TimeUtils_hdr",
],
)

112
tools/viewer/RiveSlide.cpp Normal file
View File

@ -0,0 +1,112 @@
/*
* Copyright 2022 Rive Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "tools/viewer/RiveSlide.h"
#include <rive/span.hpp>
#include <skia_renderer.hpp>
#include <skia_factory.hpp>
#include "include/core/SkCanvas.h"
#include "include/core/SkTime.h"
#include "tools/timer/TimeUtils.h"
static rive::SkiaFactory gFactory;
RiveSlide::RiveSlide(const SkString& name, const SkString& path) : fPath(path) {}
void RiveSlide::load(SkScalar w, SkScalar h) {
FILE* f = fopen(fPath.c_str(), "rb");
if (!f) {
return;
}
auto data = SkData::MakeFromFILE(f);
auto span = rive::Span<const uint8_t>((const uint8_t*)data->data(), data->size());
fFile = rive::File::import(span, &gFactory);
fclose(f);
if (fFile) {
fArtboard = fFile->artboardAt(0);
fScene = fArtboard->stateMachineAt(0);
if (!fScene) {
fScene = fArtboard->animationAt(0);
}
auto b = fScene->bounds();
fBounds = SkRect{b.left(), b.top(), b.right(), b.bottom()};
}
this->resize(w, h);
}
void RiveSlide::unload() {
fScene = nullptr;
fArtboard = nullptr;
fFile = nullptr;
}
void RiveSlide::resize(SkScalar w, SkScalar h) {
fWinSize = { w, h };
if (fScene) {
fMat = SkMatrix::RectToRect(fBounds, SkRect::MakeWH(w, h), SkMatrix::kCenter_ScaleToFit);
}
}
SkISize RiveSlide::getDimensions() const {
return fWinSize.toCeil();
}
void RiveSlide::draw(SkCanvas* canvas) {
if (fScene) {
rive::SkiaRenderer renderer(canvas);
canvas->save();
canvas->concat(fMat);
fScene->draw(&renderer);
canvas->restore();
}
}
static double nanos_to_secs(double nanos) {
return nanos * 1e-9;
}
bool RiveSlide::animate(double nanos) {
const double secs = nanos_to_secs(nanos);
if (fScene) {
if (!fSecsBase) {
// Reset the animation time.
fSecsBase = secs;
}
fScene->advanceAndApply(secs - fSecsBase);
fSecsBase = secs;
return true;
}
return false;
}
bool RiveSlide::onMouse(SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey) {
if (fScene) {
SkMatrix inverse;
if (!fMat.invert(&inverse)) {
return false;
}
auto pt = inverse.mapXY(x, y);
auto pos = rive::Vec2D(pt.fX, pt.fY);
switch (state) {
case skui::InputState::kUp: fScene->pointerUp(pos); break;
case skui::InputState::kDown: fScene->pointerDown(pos); break;
case skui::InputState::kMove: fScene->pointerMove(pos); break;
default: break;
}
return true;
}
return false;
}

53
tools/viewer/RiveSlide.h Normal file
View File

@ -0,0 +1,53 @@
/*
* Copyright 2022 Rive Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef RiveSlide_DEFINED
#define RiveSlide_DEFINED
#include "tools/viewer/Slide.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkRect.h"
#include <rive/artboard.hpp>
#include <rive/file.hpp>
#include <rive/animation/state_machine_instance.hpp>
#include <rive/animation/linear_animation_instance.hpp>
#include <vector>
class RiveSlide : public Slide {
public:
RiveSlide(const SkString& name, const SkString& path);
~RiveSlide() override = default;
void load(SkScalar winWidth, SkScalar winHeight) override;
void unload() override;
void resize(SkScalar, SkScalar) override;
SkISize getDimensions() const override;
void draw(SkCanvas*) override;
bool animate(double) override;
bool onMouse(SkScalar, SkScalar, skui::InputState, skui::ModifierKey) override;
private:
const SkString fPath;
SkSize fWinSize;
double fSecsBase = 0;
SkRect fBounds;
SkMatrix fMat;
std::unique_ptr<rive::File> fFile;
std::unique_ptr<rive::ArtboardInstance> fArtboard;
std::unique_ptr<rive::Scene> fScene;
using INHERITED = Slide;
};
#endif // RiveSlide_DEFINED

View File

@ -76,6 +76,8 @@
#include "tools/viewer/SkottieSlide.h"
#endif
#include "tools/viewer/RiveSlide.h"
#if defined(SK_ENABLE_SVG)
#include "modules/svg/include/SkSVGOpenTypeSVGDecoder.h"
#endif
@ -176,6 +178,8 @@ static DEFINE_string(lotties, PATH_PREFIX "lotties", "Directory to read (Bodymov
static DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file.");
static DEFINE_string(rives, "", "Directory to read RIVs from, or a single .riv file.");
static DEFINE_int_2(threads, j, -1,
"Run threadsafe tests on a threadpool with this many extra threads, "
"defaulting to one extra thread per core.");
@ -784,6 +788,10 @@ void Viewer::initSlides() {
return sk_make_sp<SkottieSlide>(name, path);}
},
#endif
{ ".riv", "rive-dir", FLAGS_rives,
[](const SkString& name, const SkString& path) -> sk_sp<Slide> {
return sk_make_sp<RiveSlide>(name, path);}
},
#if defined(SK_ENABLE_SVG)
{ ".svg", "svg-dir", FLAGS_svgs,
[](const SkString& name, const SkString& path) -> sk_sp<Slide> {