File: ambient_animation_static_resources.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (76 lines) | stat: -rw-r--r-- 3,075 bytes parent folder | download | duplicates (6)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_AMBIENT_RESOURCES_AMBIENT_ANIMATION_STATIC_RESOURCES_H_
#define ASH_AMBIENT_RESOURCES_AMBIENT_ANIMATION_STATIC_RESOURCES_H_

#include <memory>
#include <string_view>

#include "ash/ash_export.h"
#include "base/containers/flat_map.h"
#include "base/memory/scoped_refptr.h"

namespace cc {
class SkottieWrapper;
}  // namespace cc

namespace gfx {
class ImageSkia;
}  // namespace gfx

namespace ash {

class AmbientUiSettings;

// Loads static resources for a given AmbientUiSettings. "Static" resources
// are those that are fixed for the lifetime of the animation, as opposed to
// dynamic ones that can change between animation cycles (photos from IMAX).
// All resources are only loaded one time internally, so callers are free to
// invoke these methods as many times as desired without having to worry about
// caching the output themselves.
//
// This class is not thread-safe, but it may be bound to any sequence (including
// the UI sequence). It does not do expensive blocking I/O.
class ASH_EXPORT AmbientAnimationStaticResources {
 public:
  // Creates an AmbientAnimationStaticResources instance that loads resources
  // for the given |ui_settings|. Returns nullptr if |ui_settings| is not
  // supported.
  //
  // If |serializable| is true, GetSkottieWrapper() will return an animation
  // that can be used for out-of-process rasterization in the graphics pipeline.
  // If false, resource creation is cheaper and uses less memory but cannot be
  // used for OOP rasterization.
  static std::unique_ptr<AmbientAnimationStaticResources> Create(
      AmbientUiSettings ui_settings,
      bool serializable);

  virtual ~AmbientAnimationStaticResources() = default;

  // Returns the Lottie animation for these settings. The returned pointer is
  // never null and always points to a valid |cc::SkottieWrapper| instance. This
  // method can never fail and is cheap to call multiple times (a new animation
  // is not re-created every time this is called).
  // TODO(esum): Add an argument where the caller specifies whether to load the
  // "portrait" or "landscape" version of this animation theme.
  virtual const scoped_refptr<cc::SkottieWrapper>& GetSkottieWrapper()
      const = 0;

  // Returns the image to use for a static asset in the animation, identified by
  // the |asset_id|. The |asset_id| is a string identifier specified when the
  // animation is built offline by UX and is embedded in the Lottie json file.
  // Asset ids are unique within each Lottie file, but not across Lottie files.
  //
  // Returns an empty ImageSkia instance if the |asset_id| is unknown.
  virtual gfx::ImageSkia GetStaticImageAsset(
      std::string_view asset_id) const = 0;

  // Returns the AmbientUiSettings that the static resources belong to.
  virtual const AmbientUiSettings& GetUiSettings() const = 0;
};

}  // namespace ash

#endif  // ASH_AMBIENT_RESOURCES_AMBIENT_ANIMATION_STATIC_RESOURCES_H_