Jonathan Ross | c1d5cc7 | 2022-11-03 22:09:39 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors |
| 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 CONTENT_BROWSER_RENDERER_HOST_SCREEN_STATE_H_ |
| 6 | #define CONTENT_BROWSER_RENDERER_HOST_SCREEN_STATE_H_ |
| 7 | |
| 8 | #include "components/viz/common/surfaces/local_surface_id.h" |
| 9 | #include "ui/display/mojom/screen_orientation.mojom.h" |
| 10 | #include "ui/gfx/geometry/size.h" |
| 11 | |
| 12 | namespace content { |
| 13 | |
| 14 | // Contains a subset of blink::VisualProperties that each contribute to define |
| 15 | // the state of the screen. Each is updated through different paths/timings. |
| 16 | // This class is used to determine once all of them are in sync so that we can |
| 17 | // begin SurfaceSync with the Renderer. |
| 18 | class ScreenState { |
| 19 | public: |
| 20 | ScreenState(); |
| 21 | ~ScreenState() = default; |
| 22 | |
| 23 | // Visual properties of the screen. |
| 24 | gfx::Size visible_viewport_size; |
| 25 | gfx::Size physical_backing_size; |
| 26 | gfx::Size screen_info_size; |
| 27 | display::mojom::ScreenOrientation orientation_type = |
| 28 | display::mojom::ScreenOrientation::kUndefined; |
| 29 | bool is_fullscreen = false; |
| 30 | |
| 31 | // True when we have unlocked the orientation, which may occur in the middle |
| 32 | // of a rotation. |
| 33 | bool has_unlocked_orientation_lock = false; |
| 34 | // True when we have been locked to an orientation that requires a rotation. |
| 35 | bool is_expecting_fullscreen_rotation = false; |
| 36 | // True when we are visual properties for Picture-in-Picture. Not used in |
| 37 | // comparisons as we want to identify before/after equality of the visual |
| 38 | // properties. |
| 39 | bool is_picture_in_picture = false; |
| 40 | // Once we've processed the first update we do not look at these propertiies |
| 41 | // on subsequent updates. As rapid changes to `visible_viewport_size` can |
| 42 | // cause re-processing. |
| 43 | bool on_physical_backing_changed_received = false; |
| 44 | bool on_sync_display_properties_changed_received = false; |
| 45 | // When entering fullscreen we throttle until there is any non-rotation |
| 46 | // update. |
| 47 | bool any_non_rotation_size_changed = false; |
| 48 | // The id allocated after we have synced the above visual properties. |
| 49 | viz::LocalSurfaceId local_surface_id; |
| 50 | |
| 51 | // Copies all values that are `valid` as defined by their class. |
| 52 | void CopyDefinedAttributes(const ScreenState& other); |
| 53 | |
| 54 | // Returns true if each of `visible_viewport_size`, `physical_backing_size`, |
| 55 | // and `orientation_type` have matching orientations to `other`. |
| 56 | bool EqualOrientations(const ScreenState& other); |
| 57 | |
| 58 | // Returns true if each of `visible_viewport_size`, `physical_backing_size`, |
| 59 | // and `orientation_type` have are rotations to `other`. |
| 60 | bool IsRotated(const ScreenState& other); |
| 61 | |
| 62 | // Returns true if each of `visible_viewport_size`, `physical_backing_size`, |
| 63 | // and `orientation_type` are valid. |
| 64 | bool IsValid(); |
| 65 | |
| 66 | // We only want to compare the equality of the visual properties, not the |
| 67 | // transitional book keeping. |
| 68 | bool EqualVisualProperties(const ScreenState& other) const; |
| 69 | |
| 70 | // Determines the orientation of the two different sizes, then returns true if |
| 71 | // they are a rotation of each other. |
| 72 | static bool IsRotation(const gfx::Size& old_size, const gfx::Size& new_size); |
| 73 | |
| 74 | // Only for use with Sizes with the same scale factor. Such as comparing |
| 75 | // changes between two Physical Backings. Returns true if there was a resize |
| 76 | // along one of the axis. |
| 77 | static bool IsSingleAxisResize(const gfx::Size& old_size, |
| 78 | const gfx::Size& new_size); |
| 79 | |
| 80 | // Compares the orientations to determine if a resize if expected. For example |
| 81 | // going from Landscape to Portrait. Whereas a Portrait-Primary to |
| 82 | // Portrait-Secondary would not expect any resize for the orientation change. |
| 83 | static bool ExpectsResizeForOrientationChange( |
| 84 | display::mojom::ScreenOrientation current, |
| 85 | display::mojom::ScreenOrientation pending); |
| 86 | }; |
| 87 | } // namespace content |
| 88 | |
| 89 | #endif // CONTENT_BROWSER_RENDERER_HOST_SCREEN_STATE_H_ |