1 // Copyright 2023 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expresso or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include "gfxstream/guest/Gralloc.h"
18 
19 namespace gfxstream {
20 
21 class GoldfishGralloc : public Gralloc {
22    public:
23     uint32_t createColorBuffer(void* rcEnc, int width, int height, uint32_t glformat) override;
24 
25     int allocate(uint32_t width, uint32_t height, uint32_t format, uint64_t usage,
26                  AHardwareBuffer** outputAhb) override;
27 
28     void acquire(AHardwareBuffer* ahb) override;
29     void release(AHardwareBuffer* ahb) override;
30 
31     int lock(AHardwareBuffer* ahb, uint8_t** ptr) override;
32     int unlock(AHardwareBuffer* ahb) override;
33 
34     uint32_t getHostHandle(native_handle_t const* handle) override;
35     uint32_t getHostHandle(const AHardwareBuffer* handle) override;
36 
37     const native_handle_t* getNativeHandle(const AHardwareBuffer* ahb) override;
38 
39     int getFormat(const native_handle_t* handle) override;
40     int getFormat(const AHardwareBuffer* handle) override;
41 
42     uint32_t getFormatDrmFourcc(const native_handle_t* handle) override;
43     uint32_t getFormatDrmFourcc(const AHardwareBuffer* handle) override;
44 
45     uint32_t getWidth(const AHardwareBuffer* ahb) override;
46     uint32_t getHeight(const AHardwareBuffer* ahb) override;
47 
48     size_t getAllocatedSize(const native_handle_t* handle) override;
49     size_t getAllocatedSize(const AHardwareBuffer* handle) override;
50 
51     int getId(const AHardwareBuffer* ahb, uint64_t* id) override;
52 
53     bool treatBlobAsImage() override;
54 };
55 
56 }  // namespace gfxstream
57