• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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 
23 namespace gfxstream {
24 namespace magma {
25 
26 class DrmDevice;
27 
28 // A Connection represents an unique magma object ID namespace.
29 // Magma objects from different connections may share the same ID.
30 class 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 
38     // Get the parent device for this connection.
39     DrmDevice& getDevice();
40 
41     // 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
58