File: view_transition_request.h

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (105 lines) | stat: -rw-r--r-- 3,604 bytes parent folder | download | duplicates (2)
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
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_VIEW_TRANSITION_VIEW_TRANSITION_REQUEST_H_
#define CC_VIEW_TRANSITION_VIEW_TRANSITION_REQUEST_H_

#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/functional/callback.h"
#include "cc/cc_export.h"
#include "cc/view_transition/view_transition_element_id.h"
#include "components/viz/common/quads/compositor_frame_transition_directive.h"
#include "components/viz/common/quads/compositor_render_pass.h"

namespace cc {

// This class represents a view transition request. It is constructed in
// Blink with an intent of translating this request into a viz directive for the
// transition to occur.
class CC_EXPORT ViewTransitionRequest {
 public:
  struct CC_EXPORT SharedElementInfo {
    SharedElementInfo();
    ~SharedElementInfo();

    viz::CompositorRenderPassId render_pass_id;
    viz::ViewTransitionElementResourceId resource_id;
  };

  using SharedElementMap = std::map<ViewTransitionElementId, SharedElementInfo>;
  using Type = viz::CompositorFrameTransitionDirective::Type;

  // Creates a Type::kCapture type of request.
  static std::unique_ptr<ViewTransitionRequest> CreateCapture(
      uint32_t document_tag,
      uint32_t shared_element_count,
      viz::NavigationID navigation_id,
      std::vector<viz::ViewTransitionElementResourceId> capture_ids,
      base::OnceClosure commit_callback);

  // Creates a Type::kAnimateRenderer type of request.
  static std::unique_ptr<ViewTransitionRequest> CreateAnimateRenderer(
      uint32_t document_tag,
      viz::NavigationID navigation_id);

  // Creates a Type::kRelease type of request.
  static std::unique_ptr<ViewTransitionRequest> CreateRelease(
      uint32_t document_tag,
      viz::NavigationID navigation_id);

  ViewTransitionRequest(ViewTransitionRequest&) = delete;
  ~ViewTransitionRequest();

  ViewTransitionRequest& operator=(ViewTransitionRequest&) = delete;

  // The callback is run when the request is sufficiently processed for us to be
  // able to begin the next step in the animation. In other words, when this
  // callback is invoked it can resolve a script promise that is gating this
  // step.
  base::OnceClosure TakeFinishedCallback() {
    return std::move(commit_callback_);
  }

  // This constructs a viz directive. Note that repeated calls to this function
  // would create a new sequence id for the directive, which means it would be
  // processed again by viz.
  viz::CompositorFrameTransitionDirective ConstructDirective(
      const SharedElementMap& shared_element_render_pass_id_map) const;

  // Returns the sequence id for this request.
  uint32_t sequence_id() const { return sequence_id_; }

  Type type() const { return type_; }

  // Testing / debugging functionality.
  std::string ToString() const;

 private:
  ViewTransitionRequest(
      Type type,
      uint32_t document_tag,
      uint32_t shared_element_count,
      viz::NavigationID navigation_id,
      std::vector<viz::ViewTransitionElementResourceId> capture_ids,
      base::OnceClosure commit_callback);

  const Type type_;
  const uint32_t document_tag_;
  const uint32_t shared_element_count_;
  const viz::NavigationID navigation_id_;
  base::OnceClosure commit_callback_;
  const uint32_t sequence_id_;
  const std::vector<viz::ViewTransitionElementResourceId> capture_resource_ids_;

  static uint32_t s_next_sequence_id_;
};

}  // namespace cc

#endif  // CC_VIEW_TRANSITION_VIEW_TRANSITION_REQUEST_H_