• 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 #include <log/log.h>
18 
19 #include "RutabagaLayer.h"
20 #include "RutabagaVirtGpu.h"
21 
22 namespace gfxstream {
23 
RutabagaVirtGpuResource(uint32_t resourceId,ResourceType resourceType,uint32_t contextId)24 RutabagaVirtGpuResource::RutabagaVirtGpuResource(uint32_t resourceId, ResourceType resourceType,
25                                                  uint32_t contextId)
26     : mContextId(contextId), mResourceId(resourceId), mResourceType(resourceType) {}
27 
~RutabagaVirtGpuResource()28 RutabagaVirtGpuResource::~RutabagaVirtGpuResource() {
29     EmulatedVirtioGpu::Get().DestroyResource(mContextId, mResourceId);
30 }
31 
createMapping(void)32 VirtGpuBlobMappingPtr RutabagaVirtGpuResource::createMapping(void) {
33     uint8_t* mapped = EmulatedVirtioGpu::Get().Map(mResourceId);
34     return std::make_shared<RutabagaVirtGpuBlobMapping>(shared_from_this(), mapped);
35 }
36 
getResourceHandle() const37 uint32_t RutabagaVirtGpuResource::getResourceHandle() const { return mResourceId; }
38 
getBlobHandle() const39 uint32_t RutabagaVirtGpuResource::getBlobHandle() const {
40     if (mResourceType != ResourceType::kBlob) {
41         ALOGE("Attempting to get blob handle for non-blob resource");
42         return -1;
43     }
44 
45     ALOGE("Unimplemented: %s", __FUNCTION__);
46     return -1;
47 }
48 
exportBlob(VirtGpuExternalHandle &)49 int RutabagaVirtGpuResource::exportBlob(VirtGpuExternalHandle&) {
50     if (mResourceType != ResourceType::kBlob) {
51         ALOGE("Attempting to export blob for non-blob resource");
52         return -1;
53     }
54 
55     ALOGE("Unimplemented: %s", __FUNCTION__);
56     return -1;
57 }
58 
wait()59 int RutabagaVirtGpuResource::wait() { return EmulatedVirtioGpu::Get().Wait(mResourceId); }
60 
transferFromHost(uint32_t offset,uint32_t size)61 int RutabagaVirtGpuResource::transferFromHost(uint32_t offset, uint32_t size) {
62     if (mResourceType != ResourceType::kPipe) {
63         ALOGE("Unexpected transferFromHost() called on non-pipe resource.");
64         return -1;
65     }
66 
67     return EmulatedVirtioGpu::Get().TransferFromHost(mContextId, mResourceId, offset, size);
68 }
69 
transferToHost(uint32_t offset,uint32_t size)70 int RutabagaVirtGpuResource::transferToHost(uint32_t offset, uint32_t size) {
71     if (mResourceType != ResourceType::kPipe) {
72         ALOGE("Unexpected transferToHost() called on non-pipe resource.");
73         return -1;
74     }
75 
76     return EmulatedVirtioGpu::Get().TransferToHost(mContextId, mResourceId, offset, size);
77 }
78 
79 }  // namespace gfxstream
80