summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/vi/layer/vi_layer.h
blob: 14e229903a4ef0445149d1e24ca237ce961307bb (plain) (blame)
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
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <memory>
#include <utility>

#include "common/common_types.h"

namespace Service::android {
class BufferItemConsumer;
class BufferQueueCore;
class BufferQueueProducer;
} // namespace Service::android

namespace Service::Nvnflinger {
enum class LayerBlending : u32;
}

namespace Service::VI {

/// Represents a single display layer.
class Layer {
public:
    /// Constructs a layer with a given ID and buffer queue.
    ///
    /// @param layer_id_ The ID to assign to this layer.
    /// @param binder_id_ The binder ID to assign to this layer.
    /// @param binder_ The buffer producer queue for this layer to use.
    ///
    Layer(u64 layer_id_, u32 binder_id_, android::BufferQueueCore& core_,
          android::BufferQueueProducer& binder_,
          std::shared_ptr<android::BufferItemConsumer>&& consumer_);
    ~Layer();

    Layer(const Layer&) = delete;
    Layer& operator=(const Layer&) = delete;

    Layer(Layer&&) = default;
    Layer& operator=(Layer&&) = delete;

    /// Gets the ID for this layer.
    u64 GetLayerId() const {
        return layer_id;
    }

    /// Gets the binder ID for this layer.
    u32 GetBinderId() const {
        return binder_id;
    }

    /// Gets a reference to the buffer queue this layer is using.
    android::BufferQueueProducer& GetBufferQueue() {
        return binder;
    }

    /// Gets a const reference to the buffer queue this layer is using.
    const android::BufferQueueProducer& GetBufferQueue() const {
        return binder;
    }

    android::BufferItemConsumer& GetConsumer() {
        return *consumer;
    }

    const android::BufferItemConsumer& GetConsumer() const {
        return *consumer;
    }

    android::BufferQueueCore& Core() {
        return core;
    }

    const android::BufferQueueCore& Core() const {
        return core;
    }

    bool IsVisible() const {
        return visible;
    }

    void SetVisibility(bool v) {
        visible = v;
    }

    bool IsOpen() const {
        return open;
    }

    bool Close() {
        return std::exchange(open, false);
    }

    bool Open() {
        return !std::exchange(open, true);
    }

    Nvnflinger::LayerBlending GetBlending() {
        return blending;
    }

    void SetBlending(Nvnflinger::LayerBlending b) {
        blending = b;
    }

private:
    const u64 layer_id;
    const u32 binder_id;
    android::BufferQueueCore& core;
    android::BufferQueueProducer& binder;
    std::shared_ptr<android::BufferItemConsumer> consumer;
    Service::Nvnflinger::LayerBlending blending;
    bool open;
    bool visible;
};

} // namespace Service::VI