summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/blink/renderer/core/animation/interpolated_svg_path_source.h
blob: e7cdaf7159ca5af9d155950324022c817eec1d43 (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
// Copyright 2015 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.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_INTERPOLATED_SVG_PATH_SOURCE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_INTERPOLATED_SVG_PATH_SOURCE_H_

#include "base/macros.h"
#include "third_party/blink/renderer/core/animation/svg_path_seg_interpolation_functions.h"
#include "third_party/blink/renderer/core/svg/svg_path_data.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

class InterpolatedSVGPathSource {
  STACK_ALLOCATED();

 public:
  InterpolatedSVGPathSource(const InterpolableList& list_value,
                            const Vector<SVGPathSegType>& path_seg_types)
      : current_index_(0),
        interpolable_path_segs_(list_value),
        path_seg_types_(path_seg_types) {
    DCHECK_EQ(interpolable_path_segs_.length(), path_seg_types_.size());
  }

  bool HasMoreData() const;
  PathSegmentData ParseSegment();

 private:
  PathCoordinates current_coordinates_;
  wtf_size_t current_index_;
  const InterpolableList& interpolable_path_segs_;
  const Vector<SVGPathSegType>& path_seg_types_;
  DISALLOW_COPY_AND_ASSIGN(InterpolatedSVGPathSource);
};

bool InterpolatedSVGPathSource::HasMoreData() const {
  return current_index_ < interpolable_path_segs_.length();
}

PathSegmentData InterpolatedSVGPathSource::ParseSegment() {
  PathSegmentData segment =
      SVGPathSegInterpolationFunctions::ConsumeInterpolablePathSeg(
          *interpolable_path_segs_.Get(current_index_),
          path_seg_types_.at(current_index_), current_coordinates_);
  current_index_++;
  return segment;
}

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_INTERPOLATED_SVG_PATH_SOURCE_H_