• 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 "VirtGpu.h"
20 
21 class StubVirtGpuBlob : public std::enable_shared_from_this<StubVirtGpuBlob>, public VirtGpuBlob {
22   public:
23     StubVirtGpuBlob(int64_t deviceHandle, uint32_t blobHandle, uint32_t resourceHandle, uint64_t size);
24     ~StubVirtGpuBlob();
25 
26     uint32_t getResourceHandle() const override;
27     uint32_t getBlobHandle() const override;
28     int wait(void) override;
29 
30     VirtGpuBlobMappingPtr createMapping(void) override;
31     int exportBlob(struct VirtGpuExternalHandle& handle) override;
32 
33     int transferFromHost(uint32_t offset, uint32_t size) override;
34     int transferToHost(uint32_t offset, uint32_t size) override;
35 
36   private:
37     // Not owned.  Really should use a ScopedFD for this, but doesn't matter since we have a
38     // singleton deviceimplemenentation anyways.
39     int64_t mDeviceHandle;
40 
41     uint32_t mBlobHandle;
42     uint32_t mResourceHandle;
43     uint64_t mSize;
44 };
45 
46 class StubVirtGpuBlobMapping : public VirtGpuBlobMapping {
47   public:
48     StubVirtGpuBlobMapping(VirtGpuBlobPtr blob, uint8_t* ptr, uint64_t size);
49     ~StubVirtGpuBlobMapping(void);
50 
51     uint8_t* asRawPtr(void) override;
52 
53   private:
54     VirtGpuBlobPtr mBlob;
55     uint8_t* mPtr;
56     uint64_t mSize;
57 };
58 
59 class StubVirtGpuDevice : public VirtGpuDevice {
60   public:
61     StubVirtGpuDevice(enum VirtGpuCapset capset);
62     virtual ~StubVirtGpuDevice();
63 
64     int64_t getDeviceHandle(void) override;
65 
66     struct VirtGpuCaps getCaps(void) override;
67 
68     VirtGpuBlobPtr createBlob(const struct VirtGpuCreateBlob& blobCreate) override;
69     VirtGpuBlobPtr createVirglBlob(uint32_t width, uint32_t height, uint32_t virglFormat);
70     VirtGpuBlobPtr importBlob(const struct VirtGpuExternalHandle& handle) override;
71 
72     int execBuffer(struct VirtGpuExecBuffer& execbuffer, const VirtGpuBlob* blob) override;
73 
74     virtual VirtGpuBlobPtr createColorBuffer(int width, int height, uint32_t glFormat);
75     virtual VirtGpuBlobPtr createColorBuffer(int size);
76 
77   private:
78     int64_t mDeviceHandle;
79 
80     struct VirtGpuCaps mCaps;
81 };
82