skia2/modules/skottie/include/ExternalLayer.h
Florin Malita fbddfbb9f3 [skottie] Introduce an external layer API
Add support for external precomp Skottie layers.  This allows embedders
to seamlessly mix custom/Lottie content.

General flow:

  * embedders register a PrecompInterceptor callback with
    the animation builder
  * at build time, Skottie invokes the callback for each pre-composed
    layer
    - the returned ExternalLayer implementation is used instead of the
      Lottie layer payload
    - (a nullptr value signals Skottie to use the usual Lottie payload)
  * at render time, ExternalLayer::render() is called to defer content
    rendering to the embedder

Also implement a sample PrecompInterceptor which attempts to substitute
precmp layers matching a given pattern with external Lottie animations:

   precomp_name: "__foo.json"  -> Animation("foo.json")

This new mechanism is a generalization of (and supersedes) the old
NestedAnimation hack - so we can remove that.

Change-Id: Id80fe11881c62b8717c2476117c7c03ad5300eef
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/288130
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Mike Reed <reed@google.com>
2020-05-06 20:31:14 +00:00

57 lines
1.7 KiB
C++

/*
* Copyright 2020 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkottieExternalLayer_DEFINED
#define SkottieExternalLayer_DEFINED
#include "include/core/SkRefCnt.h"
class SkCanvas;
struct SkSize;
namespace skottie {
/**
* Interface for externally-rendered layers.
*/
class ExternalLayer : public SkRefCnt {
public:
/** Render layer content into the given canvas.
*
* @param canvas Destination canvas
* @param t Time in seconds, relative to the layer in-point (start time)
*/
virtual void render(SkCanvas* canvas, double t) = 0;
};
/**
* Interface for intercepting pre-composed layer creation.
*
* Embedders can register interceptors with animation builders, to substitute target layers
* with arbitrary/externally-controlled content (see ExternalLayer above).
*/
class PrecompInterceptor : public SkRefCnt {
public:
/**
* Invoked at animation build time, for each precomp layer.
*
* @param id The target composition ID (usually assigned automatically by BM: comp_0, ...)
* @param name The name of the precomp layer (by default it matches the target comp name,
* but can be changed in AE)
* @param size Lottie-specified precomp layer size
* @return An ExternalLayer implementation (to be used instead of the actual Lottie file
* content), or nullptr (to use the Lottie file content).
*/
virtual sk_sp<ExternalLayer> onLoadPrecomp(const char id[],
const char name[],
const SkSize& size) = 0;
};
} // namespace
#endif // SkottieExternalLayer_DEFINED