android_external_minigbm/cros_gralloc/cros_gralloc_driver.h
Ryan Neph 6d687b7b62 Revert "gralloc: Error when locking buffer alloc'd without CPU_ usage"
This reverts commit eb0e5fa310.

Reason for revert: fix ARCVM test regressions while investigating root cause (b/371862010).

Original change's description:
> gralloc: Error when locking buffer alloc'd without CPU_ usage
>
> ... except when running with software rendering as apps do not
> know that they would need to request additional CPU_* usage
> for GPU_* usage.
>
> Bug: b/356845188
> Test: cts -m CtsNativeHardwareTestCases
> Change-Id: I3536d80469d2187550558e9d02795896de4f9827
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/5893718
> Reviewed-by: Ryan Neph <ryanneph@google.com>
> Reviewed-by: Juston Li <justonli@google.com>
> Tested-by: Ryan Neph <ryanneph@google.com>
> Tested-by: Juston Li <justonli@google.com>
> Commit-Queue: Ryan Neph <ryanneph@google.com>
> Commit-Queue: Jason Macnak <natsu@google.com>

Bug: b/371862010
Change-Id: Id16c3ae1989fec9d7cd71c24b9c6d55c3d29ae45
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/5915946
Auto-Submit: Ryan Neph <ryanneph@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: ChromeOS Auto Retry <chromeos-auto-retry@chromeos-bot.iam.gserviceaccount.com>
2024-10-08 20:42:45 +00:00

89 lines
2.9 KiB
C++

/*
* Copyright 2017 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 CROS_GRALLOC_DRIVER_H
#define CROS_GRALLOC_DRIVER_H
#include "cros_gralloc_buffer.h"
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#if ANDROID_API_LEVEL >= 31 && defined(HAS_DMABUF_SYSTEM_HEAP)
#include <BufferAllocator/BufferAllocator.h>
#endif
class cros_gralloc_driver
{
public:
~cros_gralloc_driver();
static std::shared_ptr<cros_gralloc_driver> get_instance();
bool is_supported(const struct cros_gralloc_buffer_descriptor *descriptor);
int32_t allocate(const struct cros_gralloc_buffer_descriptor *descriptor,
native_handle_t **out_handle);
int32_t retain(buffer_handle_t handle);
int32_t release(buffer_handle_t handle);
int32_t lock(buffer_handle_t handle, int32_t acquire_fence, bool close_acquire_fence,
const struct rectangle *rect, uint32_t map_flags,
uint8_t *addr[DRV_MAX_PLANES]);
int32_t unlock(buffer_handle_t handle, int32_t *release_fence);
int32_t invalidate(buffer_handle_t handle);
int32_t flush(buffer_handle_t handle);
int32_t get_backing_store(buffer_handle_t handle, uint64_t *out_store);
int32_t resource_info(buffer_handle_t handle, uint32_t strides[DRV_MAX_PLANES],
uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier);
uint32_t get_resolved_drm_format(uint32_t drm_format, uint64_t use_flags);
void with_buffer(cros_gralloc_handle_t hnd,
const std::function<void(cros_gralloc_buffer *)> &function);
void with_each_buffer(const std::function<void(cros_gralloc_buffer *)> &function);
private:
cros_gralloc_driver();
bool is_initialized();
cros_gralloc_buffer *get_buffer(cros_gralloc_handle_t hnd);
bool
get_resolved_format_and_use_flags(const struct cros_gralloc_buffer_descriptor *descriptor,
uint32_t *out_format, uint64_t *out_use_flags);
int create_reserved_region(const std::string &buffer_name, uint64_t reserved_region_size);
#if ANDROID_API_LEVEL >= 31 && defined(HAS_DMABUF_SYSTEM_HEAP)
/* For allocating cros_gralloc_buffer reserved regions for metadata. */
BufferAllocator allocator_;
#endif
std::unique_ptr<struct driver, void (*)(struct driver *)> drv_;
struct cros_gralloc_imported_handle_info {
/*
* The underlying buffer for referred to by this handle (as multiple handles can
* refer to the same buffer).
*/
cros_gralloc_buffer *buffer = nullptr;
/* The handle's refcount as a handle can be imported multiple times.*/
int32_t refcount = 1;
};
std::mutex mutex_;
std::unordered_map<uint32_t, std::unique_ptr<cros_gralloc_buffer>> buffers_;
std::unordered_map<cros_gralloc_handle_t, cros_gralloc_imported_handle_info> handles_;
/* TODO(b/242184599): remove after SwiftShader is moved to the host. */
const bool is_running_with_software_rendering_ = false;
};
#endif