carnelian/view/strategies/
base.rs

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use crate::app::strategies::framebuffer::{CoordinatorProxyPtr, DisplayId};
use crate::geometry::{IntSize, Size};
use crate::view::{UserInputMessage, ViewAssistantPtr, ViewDetails};
use crate::{ViewAssistantContext, ViewKey};
use anyhow::Error;
use async_trait::async_trait;

#[async_trait(?Send)]
pub(crate) trait ViewStrategy {
    fn initial_metrics(&self) -> Size {
        Size::zero()
    }

    fn initial_physical_size(&self) -> Size {
        Size::zero()
    }

    fn initial_logical_size(&self) -> Size {
        Size::zero()
    }

    fn create_view_assistant_context(&self, _view_details: &ViewDetails) -> ViewAssistantContext;

    fn setup(&mut self, _view_details: &ViewDetails, _view_assistant: &mut ViewAssistantPtr);
    async fn render(
        &mut self,
        view_details: &ViewDetails,
        view_assistant: &mut ViewAssistantPtr,
    ) -> bool;
    fn present(&mut self, view_details: &ViewDetails);
    fn present_done(
        &mut self,
        _view_details: &ViewDetails,
        _view_assistant: &mut ViewAssistantPtr,
        _info: fidl_fuchsia_scenic_scheduling::FramePresentedInfo,
    ) {
    }

    fn convert_user_input_message(
        &mut self,
        view_details: &ViewDetails,
        _: UserInputMessage,
    ) -> Result<Vec<crate::input::Event>, Error>;

    fn inspect_event(&mut self, _view_details: &ViewDetails, _event: &crate::input::Event) {}

    fn handle_focus(
        &mut self,
        _view_details: &ViewDetails,
        _view_assistant: &mut ViewAssistantPtr,
        _: bool,
    );

    fn image_freed(&mut self, _image_id: u64, _collection_id: u32) {}

    fn render_requested(&mut self) {}

    fn ownership_changed(&mut self, _owned: bool) {}
    fn drop_display_resources(&mut self) {}

    fn handle_on_next_frame_begin(
        &mut self,
        _info: &fidl_fuchsia_ui_composition::OnNextFrameBeginValues,
    ) {
    }

    async fn handle_display_coordinator_listener_request(
        &mut self,
        _event: fidl_fuchsia_hardware_display::CoordinatorListenerRequest,
    ) {
    }

    fn is_hosted_on_display(&self, _display_id: DisplayId) -> bool {
        false
    }

    fn close(&mut self) {}
}

pub(crate) type ViewStrategyPtr = Box<dyn ViewStrategy>;

#[derive(Debug)]
pub(crate) struct DisplayDirectParams {
    pub view_key: Option<ViewKey>,
    pub coordinator: CoordinatorProxyPtr,
    pub info: fidl_fuchsia_hardware_display::Info,
    pub preferred_size: IntSize,
}

#[derive(Debug)]
pub(crate) struct FlatlandParams {
    pub args: fidl_fuchsia_ui_app::CreateView2Args,
    pub debug_name: Option<String>,
}

#[derive(Debug)]
pub(crate) enum ViewStrategyParams {
    Flatland(FlatlandParams),
    DisplayDirect(DisplayDirectParams),
}

impl ViewStrategyParams {
    pub fn view_key(&self) -> Option<ViewKey> {
        match self {
            ViewStrategyParams::DisplayDirect(params) => {
                params.view_key.or_else(|| Some(ViewKey(params.info.id.value)))
            }
            _ => None,
        }
    }

    pub fn display_id(&self) -> Option<DisplayId> {
        match self {
            ViewStrategyParams::DisplayDirect(params) => Some(params.info.id.into()),
            _ => None,
        }
    }
}