File: paint_chunk.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (110 lines) | stat: -rw-r--r-- 4,107 bytes parent folder | download | duplicates (7)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/graphics/paint/paint_chunk.h"

#include "base/memory/values_equivalent.h"
#include "third_party/blink/renderer/platform/graphics/paint/drawing_display_item.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_artifact.h"
#include "third_party/blink/renderer/platform/wtf/size_assertions.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace blink {

struct SameSizeAsPaintChunk {
  wtf_size_t begin_index;
  wtf_size_t end_index;
  PaintChunk::Id id;
  PaintChunk::BackgroundColorInfo background_color;
  TraceablePropertyTreeState properties;
  Member<HitTestData> hit_test_data;
  Member<RegionCaptureData> region_capture_data;
  Member<LayerSelectionData> layer_selection;
  gfx::Rect bounds;
  gfx::Rect drawable_bounds;
  gfx::Rect rect_known_to_be_opaque;
  uint8_t raster_effect_outset;
  uint8_t hit_test_opaqueness;
  bool b;
};

ASSERT_SIZE(PaintChunk, SameSizeAsPaintChunk);

bool PaintChunk::EqualsForUnderInvalidationChecking(
    const PaintChunk& other) const {
  return size() == other.size() && id == other.id &&
         properties == other.properties && bounds == other.bounds &&
         base::ValuesEquivalent(hit_test_data, other.hit_test_data) &&
         base::ValuesEquivalent(region_capture_data,
                                other.region_capture_data) &&
         drawable_bounds == other.drawable_bounds &&
         raster_effect_outset == other.raster_effect_outset &&
         hit_test_opaqueness == other.hit_test_opaqueness &&
         effectively_invisible == other.effectively_invisible;
  // Derived fields like rect_known_to_be_opaque are not checked because they
  // are updated when we create the next chunk or release chunks. We ensure
  // their correctness with unit tests and under-invalidation checking of
  // display items.
}

size_t PaintChunk::MemoryUsageInBytes() const {
  size_t total_size = sizeof(*this);
  if (hit_test_data) {
    total_size += sizeof(*hit_test_data);
    total_size += hit_test_data->touch_action_rects.CapacityInBytes();
    total_size += hit_test_data->wheel_event_rects.CapacityInBytes();
  }
  if (region_capture_data) {
    total_size += sizeof(*region_capture_data);
  }
  if (layer_selection_data) {
    total_size += sizeof(*layer_selection_data);
  }
  return total_size;
}

static String ToStringImpl(const PaintChunk& c,
                           const String& id_string,
                           bool concise) {
  StringBuilder sb;
  sb.AppendFormat("PaintChunk(%u-%u id=%s cacheable=%d bounds=%s from_cache=%d",
                  c.begin_index, c.end_index, id_string.Utf8().c_str(),
                  c.is_cacheable, c.bounds.ToString().c_str(),
                  c.is_moved_from_cached_subsequence);
  if (!concise) {
    sb.AppendFormat(
        " props=(%s) rect_known_to_be_opaque=%s hit_test_opaqueness=%s "
        "effectively_invisible=%d drawscontent=%d",
        c.properties.ToString().Utf8().c_str(),
        c.rect_known_to_be_opaque.ToString().c_str(),
        cc::HitTestOpaquenessToString(c.hit_test_opaqueness),
        c.effectively_invisible, c.DrawsContent());
    if (c.hit_test_data) {
      sb.Append(" hit_test_data=");
      sb.Append(c.hit_test_data->ToString());
    }
    if (c.region_capture_data) {
      sb.Append(" region_capture_data=");
      sb.Append(c.region_capture_data->ToString());
    }
  }
  sb.Append(')');
  return sb.ToString();
}

String PaintChunk::ToString(bool concise) const {
  return ToStringImpl(*this, id.ToString(), concise);
}

String PaintChunk::ToString(const PaintArtifact& paint_artifact,
                            bool concise) const {
  return ToStringImpl(*this, id.ToString(paint_artifact), concise);
}

std::ostream& operator<<(std::ostream& os, const PaintChunk& chunk) {
  return os << chunk.ToString().Utf8();
}

}  // namespace blink