summaryrefslogtreecommitdiff
path: root/cros_gralloc/gralloc4/CrosGralloc4Mapper.h
blob: c8f4afe7ec4fdb7e1a1c69bdd70144da92eb01e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * Copyright 2020 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <android/hardware/graphics/mapper/4.0/IMapper.h>

#include <memory>

#include "cros_gralloc/cros_gralloc_driver.h"
#include "cros_gralloc/cros_gralloc_handle.h"

class CrosGralloc4Mapper : public android::hardware::graphics::mapper::V4_0::IMapper {
  public:
    CrosGralloc4Mapper() = default;

    android::hardware::Return<void> createDescriptor(const BufferDescriptorInfo& description,
                                                     createDescriptor_cb hidlCb) override;

    android::hardware::Return<void> importBuffer(const android::hardware::hidl_handle& rawHandle,
                                                 importBuffer_cb hidlCb) override;

    android::hardware::Return<android::hardware::graphics::mapper::V4_0::Error> freeBuffer(
            void* rawHandle) override;

    android::hardware::Return<android::hardware::graphics::mapper::V4_0::Error> validateBufferSize(
            void* rawHandle, const BufferDescriptorInfo& descriptor, uint32_t stride) override;

    android::hardware::Return<void> getTransportSize(void* rawHandle,
                                                     getTransportSize_cb hidlCb) override;

    android::hardware::Return<void> lock(void* rawHandle, uint64_t cpuUsage,
                                         const Rect& accessRegion,
                                         const android::hardware::hidl_handle& acquireFence,
                                         lock_cb hidlCb) override;

    android::hardware::Return<void> unlock(void* rawHandle, unlock_cb hidlCb) override;

    android::hardware::Return<void> flushLockedBuffer(void* rawHandle,
                                                      flushLockedBuffer_cb hidlCb) override;

    android::hardware::Return<android::hardware::graphics::mapper::V4_0::Error> rereadLockedBuffer(
            void* rawHandle) override;

    android::hardware::Return<void> isSupported(const BufferDescriptorInfo& descriptor,
                                                isSupported_cb hidlCb) override;

    android::hardware::Return<void> get(void* rawHandle, const MetadataType& metadataType,
                                        get_cb hidlCb) override;

    android::hardware::Return<android::hardware::graphics::mapper::V4_0::Error> set(
            void* rawHandle, const MetadataType& metadataType,
            const android::hardware::hidl_vec<uint8_t>& metadata) override;

    android::hardware::Return<void> getFromBufferDescriptorInfo(
            const BufferDescriptorInfo& descriptor, const MetadataType& metadataType,
            getFromBufferDescriptorInfo_cb hidlCb) override;

    android::hardware::Return<void> listSupportedMetadataTypes(
            listSupportedMetadataTypes_cb hidlCb) override;

    android::hardware::Return<void> dumpBuffer(void* rawHandle, dumpBuffer_cb hidlCb) override;
    android::hardware::Return<void> dumpBuffers(dumpBuffers_cb hidlCb) override;

    android::hardware::Return<void> getReservedRegion(void* rawHandle,
                                                      getReservedRegion_cb hidlCb) override;

  private:
    android::hardware::Return<void> get(const cros_gralloc_buffer* crosBuffer,
                                        const MetadataType& metadataType, get_cb hidlCb);

    android::hardware::graphics::mapper::V4_0::Error set(
            cros_gralloc_buffer* crosBuffer, const MetadataType& metadataType,
            const android::hardware::hidl_vec<uint8_t>& metadata);

    android::hardware::Return<void> dumpBuffer(const cros_gralloc_buffer* crosBuffer,
                                               dumpBuffer_cb hidlCb);

    int getResolvedDrmFormat(android::hardware::graphics::common::V1_2::PixelFormat pixelFormat,
                             uint64_t bufferUsage, uint32_t* outDrmFormat);

    std::shared_ptr<cros_gralloc_driver> mDriver = cros_gralloc_driver::get_instance();
};

extern "C" android::hardware::graphics::mapper::V4_0::IMapper* HIDL_FETCH_IMapper(const char* name);