• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <memory>
20 
21 #include "VirtGpu.h"
22 
23 namespace gfxstream {
24 
25 // Virtio GPU abstraction that directly runs a host render server.
26 
27 class RutabagaVirtGpuDevice;
28 
29 class RutabagaVirtGpuBlobMapping : public VirtGpuBlobMapping {
30   public:
31     RutabagaVirtGpuBlobMapping(VirtGpuBlobPtr blob, uint8_t* mapped);
32     ~RutabagaVirtGpuBlobMapping();
33 
34     uint8_t* asRawPtr(void) override;
35 
36   private:
37     VirtGpuBlobPtr mBlob;
38     uint8_t* mMapped = nullptr;
39 };
40 
41 class RutabagaVirtGpuResource : public std::enable_shared_from_this<RutabagaVirtGpuResource>, public VirtGpuBlob {
42   public:
43     ~RutabagaVirtGpuResource();
44 
45     VirtGpuBlobMappingPtr createMapping(void) override;
46 
47     uint32_t getResourceHandle() const override;
48     uint32_t getBlobHandle() const override;
49 
50     int exportBlob(VirtGpuExternalHandle& handle) override;
51     int wait() override;
52 
53     int transferFromHost(uint32_t offset, uint32_t size) override;
54     int transferToHost(uint32_t offset, uint32_t size) override;
55 
56   private:
57     friend class RutabagaVirtGpuDevice;
58 
59     enum class ResourceType {
60         kBlob,
61         kPipe,
62     };
63 
64     RutabagaVirtGpuResource(uint32_t resourceId,
65                             ResourceType resourceType,
66                             uint32_t contextId);
67 
68 
69     const uint32_t mContextId;
70     const uint32_t mResourceId;
71     const ResourceType mResourceType;
72 };
73 
74 class RutabagaVirtGpuDevice : public std::enable_shared_from_this<RutabagaVirtGpuDevice>, public VirtGpuDevice {
75   public:
76     RutabagaVirtGpuDevice(uint32_t contextId, VirtGpuCapset capset);
77     ~RutabagaVirtGpuDevice();
78 
79     int64_t getDeviceHandle() override;
80 
81     VirtGpuCaps getCaps() override;
82 
83     VirtGpuBlobPtr createBlob(const struct VirtGpuCreateBlob& blobCreate) override;
84 
85     VirtGpuBlobPtr createVirglBlob(uint32_t width, uint32_t height, uint32_t virglFormat) override;
86 
87     VirtGpuBlobPtr importBlob(const struct VirtGpuExternalHandle& handle) override;
88 
89     int execBuffer(struct VirtGpuExecBuffer& execbuffer, const VirtGpuBlob* blob) override;
90 
91    private:
92     const uint32_t mContextId;
93     const VirtGpuCapset mCapset;
94 
95     friend class RutabagaVirtGpuResource;
GetContextId()96     uint32_t GetContextId() const { return mContextId; }
97 };
98 
99 }  // namespace gfxstream
100