summaryrefslogtreecommitdiff
path: root/cros_gralloc/aidl/Allocator.h
blob: be06dbb2946e7f6698132de17f314bc4f278c52f (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
/*
 * Copyright 2022 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.
 */

#ifndef MINIGBM_CROSGRALLOC_AIDL_ALLOCATOR_H_
#define MINIGBM_CROSGRALLOC_AIDL_ALLOCATOR_H_

#include <aidl/android/hardware/graphics/allocator/AllocationResult.h>
#include <aidl/android/hardware/graphics/allocator/BnAllocator.h>
#include <android/hardware/graphics/mapper/4.0/IMapper.h>

#include "cros_gralloc/cros_gralloc_driver.h"
#include "cros_gralloc/cros_gralloc_helpers.h"
#include "cros_gralloc/gralloc4/CrosGralloc4Metadata.h"

namespace aidl::android::hardware::graphics::allocator::impl {

class Allocator : public BnAllocator {
  public:
    Allocator() = default;

    bool init();

    ndk::ScopedAStatus allocate(const std::vector<uint8_t>& descriptor, int32_t count,
                                allocator::AllocationResult* outResult) override;

    ndk::ScopedAStatus allocate2(const BufferDescriptorInfo& descriptor, int32_t count,
                                 allocator::AllocationResult* outResult) override;

    ndk::ScopedAStatus isSupported(const BufferDescriptorInfo& descriptor,
                                   bool* outResult) override;

    ndk::ScopedAStatus getIMapperLibrarySuffix(std::string* outResult) override;

  protected:
    ndk::SpAIBinder createBinder() override;

  private:
    using Dataspace = aidl::android::hardware::graphics::common::Dataspace;
    ndk::ScopedAStatus allocate(
            const ::android::hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo&
                    descriptor,
            int32_t* outStride, native_handle_t** outHandle,
            Dataspace initialDataspace = Dataspace::UNKNOWN);

    ndk::ScopedAStatus initializeMetadata(
            cros_gralloc_handle_t crosHandle,
            const struct cros_gralloc_buffer_descriptor& crosDescriptor,
            Dataspace initialDataspace);

    void releaseBufferAndHandle(native_handle_t* handle);

    std::shared_ptr<cros_gralloc_driver> mDriver;
};

}  // namespace aidl::android::hardware::graphics::allocator::impl

#endif