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 StubVirtGpuResource : public std::enable_shared_from_this<StubVirtGpuResource>, 22 public VirtGpuResource { 23 public: 24 StubVirtGpuResource(int64_t deviceHandle, uint32_t blobHandle, uint32_t resourceHandle, 25 uint64_t size); 26 ~StubVirtGpuResource(); 27 28 uint32_t getResourceHandle() const override; 29 uint32_t getBlobHandle() const override; 30 int wait(void) 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 StubVirtGpuResourceMapping : public VirtGpuResourceMapping { 49 public: 50 StubVirtGpuResourceMapping(VirtGpuResourcePtr blob, uint8_t* ptr, uint64_t size); 51 ~StubVirtGpuResourceMapping(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 StubVirtGpuDevice : public VirtGpuDevice { 62 public: 63 StubVirtGpuDevice(enum VirtGpuCapset capset); 64 virtual ~StubVirtGpuDevice(); 65 66 int64_t getDeviceHandle(void) override; 67 68 struct VirtGpuCaps getCaps(void) override; 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, uint32_t bind); 73 VirtGpuResourcePtr importBlob(const struct VirtGpuExternalHandle& handle) override; 74 75 int execBuffer(struct VirtGpuExecBuffer& execbuffer, const VirtGpuResource* blob) override; 76 77 virtual VirtGpuResourcePtr createColorBuffer(int width, int height, uint32_t glFormat); 78 virtual VirtGpuResourcePtr createColorBuffer(int size); 79 80 private: 81 int64_t mDeviceHandle; 82 83 struct VirtGpuCaps mCaps; 84 }; 85