1// Copyright 2018 The Fuchsia 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.
45use crate::client::Client;
6use crate::object::{ObjectRef, RequestReceiver};
7use anyhow::{format_err, Error};
8use wayland_server_protocol::*;
9use {fuchsia_trace as ftrace, fuchsia_wayland_core as wl};
1011/// The set of pixel formats that will be announced to clients.
12/// Note: We don't actually support any shm formats but not reporting these as
13/// supported will confuse Sommelier even if they will never be used. Sommelier
14/// will use dmabuf protocol as that is available.
15const SUPPORTED_PIXEL_FORMATS: &[wl_shm::Format] =
16&[wl_shm::Format::Argb8888, wl_shm::Format::Xrgb8888];
1718/// The wl_shm global.
19pub struct Shm;
2021impl Shm {
22/// Creates a new `Shm`.
23pub fn new() -> Self {
24Self
25}
2627/// Posts an event back to the client for each supported SHM pixel format.
28pub fn post_formats(&self, this: wl::ObjectId, client: &Client) -> Result<(), Error> {
29ftrace::duration!(c"wayland", c"Shm::post_formats");
30for format in SUPPORTED_PIXEL_FORMATS.iter() {
31 client.event_queue().post(this, WlShmEvent::Format { format: *format })?;
32 }
33Ok(())
34 }
35}
3637impl RequestReceiver<WlShm> for Shm {
38fn receive(
39 _this: ObjectRef<Self>,
40 _request: WlShmRequest,
41 _client: &mut Client,
42 ) -> Result<(), Error> {
43Err(format_err!("Shm::receive not supported"))
44 }
45}