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
// Copyright 2018 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::client::Client,
    crate::compositor::Surface,
    crate::object::{NewObjectExt, ObjectRef, RequestReceiver},
    anyhow::Error,
    fuchsia_wayland_core as wl,
    zcr_alpha_compositing_v1_server_protocol::{
        ZcrAlphaCompositingV1, ZcrAlphaCompositingV1Request, ZcrBlendingV1, ZcrBlendingV1Request,
    },
};

/// An implementation of the zcr_alpha_compositing_v1 global.
pub struct AlphaCompositing;

impl AlphaCompositing {
    /// Creates a new `AlphaCompositing`.
    pub fn new() -> Self {
        AlphaCompositing
    }
}

impl RequestReceiver<ZcrAlphaCompositingV1> for AlphaCompositing {
    fn receive(
        this: ObjectRef<Self>,
        request: ZcrAlphaCompositingV1Request,
        client: &mut Client,
    ) -> Result<(), Error> {
        match request {
            ZcrAlphaCompositingV1Request::Destroy => {
                client.delete_id(this.id())?;
            }
            ZcrAlphaCompositingV1Request::GetBlending { id, surface } => {
                id.implement(client, AlphaBlending::new(surface))?;
            }
        }
        Ok(())
    }
}

struct AlphaBlending {
    _surface_ref: ObjectRef<Surface>,
}

impl AlphaBlending {
    pub fn new(surface: wl::ObjectId) -> Self {
        AlphaBlending { _surface_ref: surface.into() }
    }
}

impl RequestReceiver<ZcrBlendingV1> for AlphaBlending {
    fn receive(
        this: ObjectRef<Self>,
        request: ZcrBlendingV1Request,
        client: &mut Client,
    ) -> Result<(), Error> {
        match request {
            ZcrBlendingV1Request::Destroy => {
                client.delete_id(this.id())?;
            }
            ZcrBlendingV1Request::SetBlending { .. } => {}
            ZcrBlendingV1Request::SetAlpha { .. } => {}
        }
        Ok(())
    }
}