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