File: paint_artifact.h

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 (99 lines) | stat: -rw-r--r-- 3,961 bytes parent folder | download | duplicates (5)
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
// Copyright 2015 The Chromium Authors
// 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_PLATFORM_GRAPHICS_PAINT_PAINT_ARTIFACT_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_PAINT_ARTIFACT_H_

#include "base/check_op.h"
#include "third_party/blink/renderer/platform/graphics/paint/display_item_list.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_chunk.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/platform_export.h"

namespace blink {

// A PaintArtifact represents the output of painting, consisting of paint chunks
// and display items (in DisplayItemList).
//
// A PaintArtifact not only represents the output of the current painting, but
// also serves as cache of individual display items and paint chunks for later
// paintings as long as the display items and paint chunks are valid.
//
// It represents a particular state of the world, and is immutable (const) and
// promises to be in a reasonable state (e.g. chunk bounding boxes computed) to
// all users, except for PaintController and unit tests.
class PLATFORM_EXPORT PaintArtifact final
    : public GarbageCollected<PaintArtifact> {
 public:
  PaintArtifact() = default;
  PaintArtifact(const PaintArtifact& other) = delete;
  PaintArtifact& operator=(const PaintArtifact& other) = delete;
  PaintArtifact(PaintArtifact&& other) = delete;
  PaintArtifact& operator=(PaintArtifact&& other) = delete;

  void Trace(Visitor* visitor) const { visitor->Trace(chunks_); }

  bool IsEmpty() const { return chunks_.empty(); }

  DisplayItemList& GetDisplayItemList() { return display_item_list_; }
  const DisplayItemList& GetDisplayItemList() const {
    return display_item_list_;
  }

  PaintChunks& GetPaintChunks() { return chunks_; }
  const PaintChunks& GetPaintChunks() const { return chunks_; }

  DisplayItemRange DisplayItemsInChunk(wtf_size_t chunk_index) const {
    DCHECK_LT(chunk_index, chunks_.size());
    auto& chunk = chunks_[chunk_index];
    return UNSAFE_TODO(
        display_item_list_.ItemsInRange(chunk.begin_index, chunk.end_index));
  }

  // Returns the approximate memory usage, excluding memory likely to be
  // shared with the embedder after copying to cc::DisplayItemList.
  size_t ApproximateUnsharedMemoryUsage() const;

  PaintRecord GetPaintRecord(const PropertyTreeState& replay_state,
                             const gfx::Rect* cull_rect = nullptr) const;

  void RecordDebugInfo(DisplayItemClientId, const String&, DOMNodeId);
  // Note that ClientDebugName() returns the debug name at the time the client
  // was last painted, which may be out-of-date for a client whose debug name
  // has changed, but not in a way that caused it to be repainted.  This can
  // happen, for example, when the 'id' or 'class' attribute on a DOM element
  // changes, but the change doesn't cause a style invalidation.
  String ClientDebugName(DisplayItemClientId) const;
  DOMNodeId ClientOwnerNodeId(DisplayItemClientId) const;
  String IdAsString(const DisplayItem::Id& id) const;

  std::unique_ptr<JSONArray> ToJSON() const;
  void AppendChunksAsJSON(
      wtf_size_t start_chunk_index,
      wtf_size_t end_chunk_index,
      JSONArray&,
      DisplayItemList::JsonOption = DisplayItemList::kDefault) const;

  void clear();

 private:
  struct ClientDebugInfo {
    String name;
    DOMNodeId owner_node_id;
    DISALLOW_NEW();
  };

  using DebugInfo = HashMap<DisplayItemClientId, ClientDebugInfo>;

  DisplayItemList display_item_list_;
  PaintChunks chunks_;
  DebugInfo debug_info_;
};

PLATFORM_EXPORT std::ostream& operator<<(std::ostream&, const PaintArtifact&);

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_PAINT_ARTIFACT_H_