• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The ChromiumOS 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 use std::sync::Weak;
6 
7 use base::AsRawDescriptor;
8 use base::RawDescriptor;
9 use base::WaitContext;
10 use metrics::Metrics;
11 
12 use crate::gpu_display_win::DisplayProperties;
13 use crate::gpu_display_win::DisplayWin;
14 use crate::DisplayEventToken;
15 use crate::DisplayT;
16 use crate::EventDevice;
17 use crate::GpuDisplay;
18 use crate::GpuDisplayExt;
19 use crate::GpuDisplayResult;
20 use crate::WindowProcedureThread;
21 
22 pub(crate) trait WinDisplayT: DisplayT {
23     /// Imports an event device into the display backend.
import_event_device( &mut self, _event_device_id: u32, _event_device: EventDevice, ) -> GpuDisplayResult<()>24     fn import_event_device(
25         &mut self,
26         _event_device_id: u32,
27         _event_device: EventDevice,
28     ) -> GpuDisplayResult<()> {
29         Ok(())
30     }
31 }
32 
33 impl GpuDisplayExt for GpuDisplay {
import_event_device(&mut self, event_device: EventDevice) -> GpuDisplayResult<u32>34     fn import_event_device(&mut self, event_device: EventDevice) -> GpuDisplayResult<u32> {
35         let new_event_device_id = self.next_id;
36         self.inner
37             .import_event_device(new_event_device_id, event_device)?;
38 
39         self.next_id += 1;
40         Ok(new_event_device_id)
41     }
42 }
43 
44 pub trait WinGpuDisplayExt {
open_winapi( wndproc_thread: WindowProcedureThread, win_metrics: Option<Weak<Metrics>>, display_properties: DisplayProperties, ) -> GpuDisplayResult<GpuDisplay>45     fn open_winapi(
46         wndproc_thread: WindowProcedureThread,
47         win_metrics: Option<Weak<Metrics>>,
48         display_properties: DisplayProperties,
49     ) -> GpuDisplayResult<GpuDisplay>;
50 }
51 
52 impl WinGpuDisplayExt for GpuDisplay {
open_winapi( wndproc_thread: WindowProcedureThread, win_metrics: Option<Weak<Metrics>>, display_properties: DisplayProperties, ) -> GpuDisplayResult<GpuDisplay>53     fn open_winapi(
54         wndproc_thread: WindowProcedureThread,
55         win_metrics: Option<Weak<Metrics>>,
56         display_properties: DisplayProperties,
57     ) -> GpuDisplayResult<GpuDisplay> {
58         let display = DisplayWin::new(wndproc_thread, win_metrics, display_properties)?;
59 
60         let wait_ctx = WaitContext::new()?;
61         wait_ctx.add(&display, DisplayEventToken::Display)?;
62 
63         Ok(GpuDisplay {
64             inner: Box::new(display),
65             next_id: 1,
66             event_devices: Default::default(),
67             surfaces: Default::default(),
68             imports: Default::default(),
69             wait_ctx,
70             is_x: false,
71         })
72     }
73 }
74 
75 impl AsRawDescriptor for GpuDisplay {
as_raw_descriptor(&self) -> RawDescriptor76     fn as_raw_descriptor(&self) -> RawDescriptor {
77         self.inner.as_raw_descriptor()
78     }
79 }
80