1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_VIZ_COMMON_QUADS_COMPOSITOR_FRAME_METADATA_H_
6 #define COMPONENTS_VIZ_COMMON_QUADS_COMPOSITOR_FRAME_METADATA_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <vector>
12
13 #include "base/optional.h"
14 #include "base/time/time.h"
15 #include "build/build_config.h"
16 #include "components/viz/common/delegated_ink_metadata.h"
17 #include "components/viz/common/frame_sinks/begin_frame_args.h"
18 #include "components/viz/common/quads/frame_deadline.h"
19 #include "components/viz/common/surfaces/surface_id.h"
20 #include "components/viz/common/surfaces/surface_range.h"
21 #include "components/viz/common/viz_common_export.h"
22 #include "third_party/skia/include/core/SkColor.h"
23 #include "ui/gfx/display_color_spaces.h"
24 #include "ui/gfx/geometry/size_f.h"
25 #include "ui/gfx/geometry/vector2d_f.h"
26 #include "ui/gfx/overlay_transform.h"
27 #include "ui/latency/latency_info.h"
28
29 #if defined(OS_ANDROID)
30 #include "components/viz/common/quads/selection.h"
31 #include "ui/gfx/selection_bound.h"
32 #endif // defined(OS_ANDROID)
33
34 namespace viz {
35
36 // Compares two frame tokens, handling cases where the token wraps around the
37 // 32-bit max value.
FrameTokenGT(uint32_t token1,uint32_t token2)38 inline bool FrameTokenGT(uint32_t token1, uint32_t token2) {
39 // There will be underflow in the subtraction if token1 was created
40 // after token2.
41 return (token2 - token1) > 0x80000000u;
42 }
43
44 class VIZ_COMMON_EXPORT FrameTokenGenerator {
45 public:
46 inline uint32_t operator++() {
47 if (++frame_token_ == 0)
48 ++frame_token_;
49 return frame_token_;
50 }
51
52 inline uint32_t operator*() const { return frame_token_; }
53
54 private:
55 uint32_t frame_token_ = 0;
56 };
57
58 class VIZ_COMMON_EXPORT CompositorFrameMetadata {
59 public:
60 CompositorFrameMetadata();
61 CompositorFrameMetadata(CompositorFrameMetadata&& other);
62 ~CompositorFrameMetadata();
63
64 CompositorFrameMetadata& operator=(CompositorFrameMetadata&& other);
65
66 CompositorFrameMetadata Clone() const;
67
68 // The device scale factor used to generate this compositor frame. Must be
69 // greater than zero.
70 float device_scale_factor = 0.f;
71
72 // Scroll offset and scale of the root layer. This can be used for tasks
73 // like positioning windowed plugins.
74 gfx::Vector2dF root_scroll_offset;
75 float page_scale_factor = 0.f;
76
77 gfx::SizeF scrollable_viewport_size;
78
79 gfx::ContentColorUsage content_color_usage = gfx::ContentColorUsage::kSRGB;
80
81 bool may_contain_video = false;
82
83 // WebView makes quality decisions for rastering resourceless software frames
84 // based on information that a scroll or animation is active.
85 // TODO(aelias): Remove this and always enable filtering if there aren't apps
86 // depending on this anymore.
87 bool is_resourceless_software_draw_with_scroll_or_animation = false;
88
89 // This color is usually obtained from the background color of the <body>
90 // element. It can be used for filling in gutter areas around the frame when
91 // it's too small to fill the box the parent reserved for it.
92 SkColor root_background_color = SK_ColorWHITE;
93
94 std::vector<ui::LatencyInfo> latency_info;
95
96 // This is the set of surfaces that the client wants to keep alive. It is
97 // guaranteed that the last activated surface in every SurfaceRange will be
98 // kept alive as long as the surface containing this CompositorFrame is alive.
99 // Note: Not every surface in this list might have a corresponding
100 // SurfaceDrawQuad, as this list also includes occluded and clipped surfaces
101 // and surfaces that may be accessed by this CompositorFrame in the future.
102 // However, every SurfaceDrawQuad MUST have a corresponding entry in this
103 // list.
104 std::vector<SurfaceRange> referenced_surfaces;
105
106 // This is the set of dependent SurfaceIds that should be active in the
107 // display compositor before this CompositorFrame can be activated.
108 // Note: |activation_dependencies| MUST be a subset of |referenced_surfaces|.
109 // TODO(samans): Rather than having a separate list for activation
110 // dependencies, each member of referenced_surfaces can have a boolean flag
111 // that determines whether activation of this particular SurfaceId blocks the
112 // activation of the CompositorFrame. https://crbug.com/938946
113 std::vector<SurfaceId> activation_dependencies;
114
115 // This specifies a deadline for this CompositorFrame to synchronize with its
116 // activation dependencies. Once this deadline passes, this CompositorFrame
117 // should be forcibly activated. This deadline may be lower-bounded by the
118 // default synchronization deadline specified by the system.
119 FrameDeadline deadline;
120
121 // BeginFrameAck for the BeginFrame that this CompositorFrame answers.
122 BeginFrameAck begin_frame_ack;
123
124 // An identifier for the frame. This is used to identify the frame for
125 // presentation-feedback, or when the frame-token is sent to the embedder.
126 // For comparing |frame_token| from different frames, use |FrameTokenGT()|
127 // instead of directly comparing them, since the tokens wrap around back to 1
128 // after the 32-bit max value.
129 // TODO(crbug.com/850386): A custom type would be better to avoid incorrect
130 // comparisons.
131 uint32_t frame_token = 0;
132
133 // Once the display compositor processes a frame with
134 // |send_frame_token_to_embedder| flag turned on, the |frame_token| for the
135 // frame is sent to embedder of the frame. This is helpful when the embedder
136 // wants to do something after a particular frame is processed.
137 bool send_frame_token_to_embedder = false;
138
139 // These limits can be used together with the scroll/scale fields above to
140 // determine if scrolling/scaling in a particular direction is possible.
141 float min_page_scale_factor = 0.f;
142
143 // The visible height of the top-controls. If the value is not set, then the
144 // visible height should be the same as in the latest submitted frame with a
145 // value set.
146 base::Optional<float> top_controls_visible_height;
147
148 base::Optional<base::TimeDelta> preferred_frame_interval;
149
150 // Display transform hint when the frame is generated. Note this is only
151 // applicable to frames of the root surface.
152 gfx::OverlayTransform display_transform_hint = gfx::OVERLAY_TRANSFORM_NONE;
153
154 // Contains the metadata required for drawing a delegated ink trail onto the
155 // end of a rendered ink stroke. This should only be present when two
156 // conditions are met:
157 // 1. The JS API |updateInkTrailStartPoint| is used - This gathers the
158 // metadata and puts it onto a compositor frame to be sent to viz.
159 // 2. This frame will not be submitted to the root surface - The browser UI
160 // does not use this, and the frame must be contained within a
161 // SurfaceDrawQuad.
162 // The ink trail created with this metadata will only last for a single frame
163 // before it disappears, regardless of whether or not the next frame contains
164 // delegated ink metadata.
165 std::unique_ptr<DelegatedInkMetadata> delegated_ink_metadata;
166
167 private:
168 CompositorFrameMetadata(const CompositorFrameMetadata& other);
169 CompositorFrameMetadata operator=(const CompositorFrameMetadata&) = delete;
170 };
171
172 } // namespace viz
173
174 #endif // COMPONENTS_VIZ_COMMON_QUADS_COMPOSITOR_FRAME_METADATA_H_
175