summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/jank_region.h
blob: 804861cbdc53cd5ae862bcc6156e0e1b1258f5b0 (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
54
55
56
57
// Copyright 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.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_JANK_REGION_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_JANK_REGION_H_

#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/geometry/int_rect.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

// Represents a per-frame jank region for JankTracker. Only used when the
// JankTrackingSweepLine feature is enabled.
//
// This class uses a sweep line algorithm to compute the area in O(n log n) time
// where n is the number of rects recorded by AddRect. For complex jank regions,
// this is more efficient than using blink::Region, which is worst-case O(n^2)
// from the repeated calls to Region::Unite.
//
// The high-level approach is described here:
// http://jeffe.cs.illinois.edu/open/klee.html
//
// The sweep line moves from left to right. (TODO: compare performance against a
// top-to-bottom sweep.)
//
// The sweep line's current intersection with the jank region ("active length")
// is tracked by a segment tree, similar to what is described at:
// https://en.wikipedia.org/wiki/Segment_tree
//
// There are some subtleties to the segment tree, which are described by the
// comments in the implementation.

class CORE_EXPORT JankRegion {
  DISALLOW_NEW();

 public:
  void AddRect(const IntRect& rect) {
    if (!rect.IsEmpty())
      rects_.push_back(rect);
  }

  const Vector<IntRect>& GetRects() const { return rects_; }
  bool IsEmpty() const { return rects_.IsEmpty(); }
  void Reset() { rects_.clear(); }

  uint64_t Area() const;

 private:
  Vector<IntRect> rects_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_JANK_REGION_H_