1 // Copyright 2018 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 CC_TREES_RENDER_FRAME_METADATA_H_
6 #define CC_TREES_RENDER_FRAME_METADATA_H_
7 
8 #include "base/optional.h"
9 #include "base/time/time.h"
10 #include "build/build_config.h"
11 #include "cc/cc_export.h"
12 #include "components/viz/common/quads/selection.h"
13 #include "components/viz/common/surfaces/local_surface_id.h"
14 #include "components/viz/common/vertical_scroll_direction.h"
15 #include "third_party/skia/include/core/SkColor.h"
16 #include "ui/gfx/geometry/size.h"
17 #include "ui/gfx/geometry/size_f.h"
18 #include "ui/gfx/geometry/vector2d_f.h"
19 #include "ui/gfx/selection_bound.h"
20 
21 namespace cc {
22 
23 class CC_EXPORT RenderFrameMetadata {
24  public:
25   RenderFrameMetadata();
26   RenderFrameMetadata(const RenderFrameMetadata& other);
27   RenderFrameMetadata(RenderFrameMetadata&& other);
28   ~RenderFrameMetadata();
29 
30   RenderFrameMetadata& operator=(const RenderFrameMetadata&);
31   RenderFrameMetadata& operator=(RenderFrameMetadata&& other);
32   bool operator==(const RenderFrameMetadata& other) const;
33   bool operator!=(const RenderFrameMetadata& other) const;
34 
35   // Indicates whether the scroll offset of the root layer is at top, i.e.,
36   // whether scroll_offset.y() == 0.
37   bool is_scroll_offset_at_top = true;
38 
39   // The background color of a CompositorFrame. It can be used for filling the
40   // content area if the primary surface is unavailable and fallback is not
41   // specified.
42   SkColor root_background_color = SK_ColorWHITE;
43 
44   // Scroll offset of the root layer.
45   base::Optional<gfx::Vector2dF> root_scroll_offset;
46 
47   // Selection region relative to the current viewport. If the selection is
48   // empty or otherwise unused, the bound types will indicate such.
49   viz::Selection<gfx::SelectionBound> selection;
50 
51   // Determines whether the page is mobile optimized or not, which means at
52   // least one of the following has to be true:
53   // - page has a width=device-width or narrower viewport.
54   // - page prevents zooming in or out (i.e. min and max page scale factors
55   // are the same).
56   bool is_mobile_optimized = false;
57 
58   // Flag used to notify the browser process to start or stop forwarding points
59   // to viz for use in a delegated ink trail. True the entire time points should
60   // be forwarded, and forwarding stops as soon as it is false again.
61   bool has_delegated_ink_metadata = false;
62 
63   // The device scale factor used to generate a CompositorFrame.
64   float device_scale_factor = 1.f;
65 
66   // The size of the viewport used to generate a CompositorFrame. Equivalent to
67   // the size of the root render pass.
68   gfx::Size viewport_size_in_pixels;
69 
70   // The last viz::LocalSurfaceId used to submit a CompositorFrame.
71   base::Optional<viz::LocalSurfaceId> local_surface_id;
72 
73   // Page scale factor (always 1.f for sub-frame renderers).
74   float page_scale_factor = 1.f;
75   // Used for testing propagation of page scale factor to sub-frame renderers.
76   float external_page_scale_factor = 1.f;
77 
78   // Used to position the location top bar and page content, whose precise
79   // position is computed by the renderer compositor.
80   float top_controls_height = 0.f;
81   float top_controls_shown_ratio = 0.f;
82 
83   // Indicates a change in the vertical scroll direction of the root layer since
84   // the last drawn render frame. If no change occurred, this value is |kNull|.
85   // Note that if a scroll in a given direction occurs, the scroll is completed,
86   // and then another scroll in the *same* direction occurs, we will not
87   // consider the second scroll event to have caused a change in direction.
88   viz::VerticalScrollDirection new_vertical_scroll_direction =
89       viz::VerticalScrollDirection::kNull;
90 
91 #if defined(OS_ANDROID)
92   // Used to position Android bottom bar, whose position is computed by the
93   // renderer compositor.
94   float bottom_controls_height = 0.f;
95   float bottom_controls_shown_ratio = 0.f;
96 
97   // Used to offset views that need to be positioned according to the current
98   // min-height. These offsets follow the min-height change animations.
99   float top_controls_min_height_offset = 0.f;
100   float bottom_controls_min_height_offset = 0.f;
101 
102   // These limits can be used together with the scroll/scale fields above to
103   // determine if scrolling/scaling in a particular direction is possible.
104   float min_page_scale_factor = 0.f;
105   float max_page_scale_factor = 0.f;
106   bool root_overflow_y_hidden = false;
107 
108   gfx::SizeF scrollable_viewport_size;
109   gfx::SizeF root_layer_size;
110 
111   // Returns whether the root RenderPass of the CompositorFrame has a
112   // transparent background color.
113   bool has_transparent_background = false;
114 #endif
115 };
116 
117 }  // namespace cc
118 
119 #endif  // CC_TREES_RENDER_FRAME_METADATA_H_
120