Zoraiz Naeem | 7eef79a | 2023-02-28 23:27:45 | [diff] [blame] | 1 | // Copyright 2023 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 ASH_ROUNDED_DISPLAY_ROUNDED_DISPLAY_HOST_H_ |
| 6 | #define ASH_ROUNDED_DISPLAY_ROUNDED_DISPLAY_HOST_H_ |
| 7 | |
Zoraiz Naeem | 7eef79a | 2023-02-28 23:27:45 | [diff] [blame] | 8 | #include <memory> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "ash/frame_sink/frame_sink_host.h" |
| 12 | #include "ash/rounded_display/rounded_display_gutter.h" |
| 13 | #include "base/functional/callback_forward.h" |
| 14 | #include "base/memory/weak_ptr.h" |
| 15 | |
| 16 | namespace viz { |
| 17 | class CompositorFrame; |
| 18 | } // namespace viz |
| 19 | |
| 20 | namespace ash { |
| 21 | class RoundedDisplayFrameFactory; |
| 22 | |
| 23 | // Renders the rounded-display mask textures by creating independent |
| 24 | // compositor frames and submitting them to the display compositor. |
| 25 | class ASH_EXPORT RoundedDisplayHost : public ash::FrameSinkHost { |
| 26 | public: |
| 27 | using GetGuttersCallback = |
| 28 | base::RepeatingCallback<void(std::vector<RoundedDisplayGutter*>&)>; |
| 29 | |
| 30 | // The callback is used to get RoundedDisplayGutters that are used to paint |
| 31 | // mask textures for compositor frames. |
| 32 | explicit RoundedDisplayHost(GetGuttersCallback callback); |
| 33 | |
| 34 | RoundedDisplayHost(const RoundedDisplayHost&) = delete; |
| 35 | RoundedDisplayHost& operator=(const RoundedDisplayHost&) = delete; |
| 36 | |
| 37 | ~RoundedDisplayHost() override; |
| 38 | |
| 39 | protected: |
| 40 | // ash::FrameSinkHost: |
| 41 | std::unique_ptr<viz::CompositorFrame> CreateCompositorFrame( |
| 42 | const viz::BeginFrameAck& begin_frame_ack, |
| 43 | UiResourceManager& resource_manager, |
| 44 | bool auto_update, |
| 45 | const gfx::Size& last_submitted_frame_size, |
| 46 | float last_submitted_frame_dsf) override; |
| 47 | |
| 48 | private: |
| 49 | // This callback is used to get RoundedDisplayGutters that know how to |
| 50 | // paint mask textures for rounded corners of a display. |
| 51 | GetGuttersCallback get_resource_generator_callback_; |
| 52 | |
| 53 | // RoundedDisplayHost delegates the work to create and configure compositor |
| 54 | // frames to the RoundedDisplayFrameFactory. |
| 55 | std::unique_ptr<RoundedDisplayFrameFactory> frame_factory_; |
| 56 | |
| 57 | base::WeakPtrFactory<RoundedDisplayHost> weak_ptr_factory_{this}; |
| 58 | }; |
| 59 | |
| 60 | } // namespace ash |
| 61 | |
| 62 | #endif // ASH_ROUNDED_DISPLAY_ROUNDED_DISPLAY_HOST_H_ |