blob: 3e0c5a3c96f98b41749b719d4488f3de06d4c4b9 [file] [log] [blame]
Matt Sandy63461de2023-04-26 12:59:44 -07001// Copyright (C) 2023 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License") override;
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <memory>
18#include <optional>
19#include <unordered_map>
20
21#include "DrmContext.h"
22
23namespace gfxstream {
24namespace magma {
25
26class DrmDevice;
27
28// A Connection represents an unique magma object ID namespace.
29// Magma objects from different connections may share the same ID.
30class Connection {
31 public:
32 Connection(DrmDevice& device);
33 ~Connection() = default;
34 DISALLOW_COPY_AND_ASSIGN(Connection);
35 Connection(Connection&&) noexcept = default;
36 Connection& operator=(Connection&&) = delete;
37
Matt Sandyf43aa8f2023-04-27 11:42:25 -070038 // Get the parent device for this connection.
39 DrmDevice& getDevice();
40
Matt Sandy63461de2023-04-26 12:59:44 -070041 // Creates a new context and returns its ID. Returns nullopt on error.
42 std::optional<uint32_t> createContext();
43
44 // Returns the context for the given ID, or nullptr if invalid.
45 DrmContext* getContext(uint32_t id);
46
47 private:
48 friend class DrmContext;
49
50 DrmDevice& mDevice;
51
52 // Maps context IDs to contexts.
53 std::unordered_map<uint32_t, DrmContext> mContexts;
54};
55
56} // namespace magma
57} // namespace gfxstream