summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/vi/layer/vi_layer.h
blob: f95e2dc714ef2fb51f0d8a1a9a5b7c96eeeac313 (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
// 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::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 IsOpen() const {
        return open;
    }

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

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

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

} // namespace Service::VI