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