gralloc1: Add remaining functionality

* Use private_0 flag
* Add some legacy flags to be used during transition
* Fix gralloc module version
* Adjust makefiles for gralloc1
* Add support for dump, num flex planes and lock flex.
* Use a unique ID for buffer descriptors
* Do not delete buffer handle, fix after verifying framework fix.
* Current gralloc1 clients do not conform to the lock() requirement
in the gralloc1 header. Tracked in b/33588773
* Add perform APIs to get the buffer size  and allocate a buffer
for use by SDM
* Fix reference counting
* Add a unique buffer ID
* Some cleanup in private_handle
* Create a wrapper class of private_handle to do refcounting
* Resolve implementation defined formats At allocation time, update buffer
descriptors to replace implementation defined formats with the ones we mean
to allocate
* Defer ion handle release
* Remove unused drm code.
* Add legacy constructor for private_handle_t used by some
clients

CRs-Fixed: 2007391
Change-Id: Ia9e816cec35ba45483a5b75d99f256325a010138
This commit is contained in:
Naseer Ahmed
2016-11-22 20:05:16 -05:00
committed by Gerrit - the friendly Code Review server
parent 441526d42f
commit e69031e9c7
13 changed files with 552 additions and 598 deletions

View File

@@ -21,6 +21,7 @@ LOCAL_COPY_HEADERS := copybit.h copybit_priv.h c2d2.h
#Copy the headers regardless of whether copybit is built #Copy the headers regardless of whether copybit is built
include $(BUILD_COPY_HEADERS) include $(BUILD_COPY_HEADERS)
ifneq ($(TARGET_USES_GRALLOC1), true)
LOCAL_MODULE := copybit.$(TARGET_BOARD_PLATFORM) LOCAL_MODULE := copybit.$(TARGET_BOARD_PLATFORM)
LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_MODULE_TAGS := optional LOCAL_MODULE_TAGS := optional
@@ -47,3 +48,4 @@ else
endif endif
endif endif
endif endif
endif

View File

@@ -29,6 +29,7 @@
#include <cutils/log.h> #include <cutils/log.h>
#include <algorithm> #include <algorithm>
#include <vector>
#include "gr_utils.h" #include "gr_utils.h"
#include "gr_allocator.h" #include "gr_allocator.h"
@@ -68,6 +69,9 @@
#define ION_SC_PREVIEW_FLAGS ION_SECURE #define ION_SC_PREVIEW_FLAGS ION_SECURE
#endif #endif
using std::vector;
using std::shared_ptr;
namespace gralloc1 { namespace gralloc1 {
Allocator::Allocator() : ion_allocator_(NULL), adreno_helper_(NULL) { Allocator::Allocator() : ion_allocator_(NULL), adreno_helper_(NULL) {
@@ -117,43 +121,6 @@ int Allocator::AllocateMem(AllocData *alloc_data, gralloc1_producer_usage_t prod
return ret; return ret;
} }
// Allocates buffer from width, height and format into a
// private_handle_t. It is the responsibility of the caller
// to free the buffer using the FreeBuffer function
int Allocator::AllocateBuffer(const BufferDescriptor &descriptor, private_handle_t **pHnd) {
AllocData data;
unsigned int aligned_w, aligned_h;
data.base = 0;
data.fd = -1;
data.offset = 0;
data.align = (unsigned int)getpagesize();
int format = descriptor.GetFormat();
gralloc1_producer_usage_t prod_usage = descriptor.GetProducerUsage();
gralloc1_consumer_usage_t cons_usage = descriptor.GetConsumerUsage();
GetBufferSizeAndDimensions(descriptor, &data.size, &aligned_w, &aligned_h);
int err = AllocateMem(&data, prod_usage, cons_usage);
if (0 != err) {
ALOGE("%s: allocate failed", __FUNCTION__);
return -ENOMEM;
}
if (IsUBwcEnabled(format, prod_usage, cons_usage)) {
data.alloc_type |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
}
// Metadata is not allocated. would be empty
private_handle_t *hnd = new private_handle_t(
data.fd, data.size, INT(data.alloc_type), 0, INT(format), INT(aligned_w), INT(aligned_h), -1,
0, 0, descriptor.GetWidth(), descriptor.GetHeight(), prod_usage, cons_usage);
hnd->base = (uint64_t)data.base;
hnd->offset = data.offset;
hnd->gpuaddr = 0;
*pHnd = hnd;
return 0;
}
int Allocator::MapBuffer(void **base, unsigned int size, unsigned int offset, int fd) { int Allocator::MapBuffer(void **base, unsigned int size, unsigned int offset, int fd) {
if (ion_allocator_) { if (ion_allocator_) {
return ion_allocator_->MapBuffer(base, size, offset, fd); return ion_allocator_->MapBuffer(base, size, offset, fd);
@@ -162,9 +129,10 @@ int Allocator::MapBuffer(void **base, unsigned int size, unsigned int offset, in
return -EINVAL; return -EINVAL;
} }
int Allocator::FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd) { int Allocator::FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd,
int handle) {
if (ion_allocator_) { if (ion_allocator_) {
return ion_allocator_->FreeBuffer(base, size, offset, fd); return ion_allocator_->FreeBuffer(base, size, offset, fd, handle);
} }
return -EINVAL; return -EINVAL;
@@ -178,8 +146,9 @@ int Allocator::CleanBuffer(void *base, unsigned int size, unsigned int offset, i
return -EINVAL; return -EINVAL;
} }
bool Allocator::CheckForBufferSharing(uint32_t num_descriptors, const BufferDescriptor *descriptors, bool Allocator::CheckForBufferSharing(uint32_t num_descriptors,
int *max_index) { const vector<shared_ptr<BufferDescriptor>>& descriptors,
ssize_t *max_index) {
unsigned int cur_heap_id = 0, prev_heap_id = 0; unsigned int cur_heap_id = 0, prev_heap_id = 0;
unsigned int cur_alloc_type = 0, prev_alloc_type = 0; unsigned int cur_alloc_type = 0, prev_alloc_type = 0;
unsigned int cur_ion_flags = 0, prev_ion_flags = 0; unsigned int cur_ion_flags = 0, prev_ion_flags = 0;
@@ -190,8 +159,8 @@ bool Allocator::CheckForBufferSharing(uint32_t num_descriptors, const BufferDesc
*max_index = -1; *max_index = -1;
for (uint32_t i = 0; i < num_descriptors; i++) { for (uint32_t i = 0; i < num_descriptors; i++) {
// Check Cached vs non-cached and all the ION flags // Check Cached vs non-cached and all the ION flags
cur_uncached = UseUncached(descriptors[i].GetProducerUsage()); cur_uncached = UseUncached(descriptors[i]->GetProducerUsage());
GetIonHeapInfo(descriptors[i].GetProducerUsage(), descriptors[i].GetConsumerUsage(), GetIonHeapInfo(descriptors[i]->GetProducerUsage(), descriptors[i]->GetConsumerUsage(),
&cur_heap_id, &cur_alloc_type, &cur_ion_flags); &cur_heap_id, &cur_alloc_type, &cur_ion_flags);
if (i > 0 && (cur_heap_id != prev_heap_id || cur_alloc_type != prev_alloc_type || if (i > 0 && (cur_heap_id != prev_heap_id || cur_alloc_type != prev_alloc_type ||
@@ -200,8 +169,8 @@ bool Allocator::CheckForBufferSharing(uint32_t num_descriptors, const BufferDesc
} }
// For same format type, find the descriptor with bigger size // For same format type, find the descriptor with bigger size
GetAlignedWidthAndHeight(descriptors[i], &alignedw, &alignedh); GetAlignedWidthAndHeight(*descriptors[i], &alignedw, &alignedh);
unsigned int size = GetSize(descriptors[i], alignedw, alignedh); unsigned int size = GetSize(*descriptors[i], alignedw, alignedh);
if (max_size < size) { if (max_size < size) {
*max_index = INT(i); *max_index = INT(i);
max_size = size; max_size = size;
@@ -552,7 +521,7 @@ void Allocator::GetIonHeapInfo(gralloc1_producer_usage_t prod_usage,
unsigned int *alloc_type, unsigned int *ion_flags) { unsigned int *alloc_type, unsigned int *ion_flags) {
unsigned int heap_id = 0; unsigned int heap_id = 0;
unsigned int type = 0; unsigned int type = 0;
int flags = 0; unsigned int flags = 0;
if (prod_usage & GRALLOC1_PRODUCER_USAGE_PROTECTED) { if (prod_usage & GRALLOC1_PRODUCER_USAGE_PROTECTED) {
if (cons_usage & GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY) { if (cons_usage & GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY) {
heap_id = ION_HEAP(SD_HEAP_ID); heap_id = ION_HEAP(SD_HEAP_ID);
@@ -597,7 +566,7 @@ void Allocator::GetIonHeapInfo(gralloc1_producer_usage_t prod_usage,
} }
*alloc_type = type; *alloc_type = type;
*ion_flags = (unsigned int)flags; *ion_flags = flags;
*ion_heap_id = heap_id; *ion_heap_id = heap_id;
return; return;

View File

@@ -36,6 +36,8 @@
#define SECURE_ALIGN SZ_1M #define SECURE_ALIGN SZ_1M
#endif #endif
#include <vector>
#include "gralloc_priv.h" #include "gralloc_priv.h"
#include "gr_buf_descriptor.h" #include "gr_buf_descriptor.h"
#include "gr_adreno_info.h" #include "gr_adreno_info.h"
@@ -48,15 +50,15 @@ class Allocator {
Allocator(); Allocator();
~Allocator(); ~Allocator();
bool Init(); bool Init();
int AllocateBuffer(const BufferDescriptor &descriptor, private_handle_t **pHnd);
int MapBuffer(void **base, unsigned int size, unsigned int offset, int fd); int MapBuffer(void **base, unsigned int size, unsigned int offset, int fd);
int FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd); int FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, int handle);
int CleanBuffer(void *base, unsigned int size, unsigned int offset, int fd, int op); int CleanBuffer(void *base, unsigned int size, unsigned int offset, int fd, int op);
int AllocateMem(AllocData *data, gralloc1_producer_usage_t prod_usage, int AllocateMem(AllocData *data, gralloc1_producer_usage_t prod_usage,
gralloc1_consumer_usage_t cons_usage); gralloc1_consumer_usage_t cons_usage);
// @return : index of the descriptor with maximum buffer size req // @return : index of the descriptor with maximum buffer size req
bool CheckForBufferSharing(uint32_t num_descriptors, const BufferDescriptor *descriptors, bool CheckForBufferSharing(uint32_t num_descriptors,
int *max_index); const std::vector<std::shared_ptr<BufferDescriptor>>& descriptors,
ssize_t *max_index);
int GetImplDefinedFormat(gralloc1_producer_usage_t prod_usage, int GetImplDefinedFormat(gralloc1_producer_usage_t prod_usage,
gralloc1_consumer_usage_t cons_usage, int format); gralloc1_consumer_usage_t cons_usage, int format);
unsigned int GetSize(const BufferDescriptor &d, unsigned int alignedw, unsigned int alignedh); unsigned int GetSize(const BufferDescriptor &d, unsigned int alignedw, unsigned int alignedh);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, The Linux Foundation. All rights reserved. * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
@@ -32,18 +32,18 @@
#include <hardware/gralloc1.h> #include <hardware/gralloc1.h>
#define BUF_DESCRIPTOR(exp) reinterpret_cast<BufferDescriptor *>(exp) namespace gralloc1 {
class BufferDescriptor { class BufferDescriptor {
public: public:
BufferDescriptor() {} BufferDescriptor() : id_(next_id_++) {}
BufferDescriptor(int w, int h, int f) BufferDescriptor(int w, int h, int f)
: width_(w), : width_(w),
height_(h), height_(h),
format_(f), format_(f),
producer_usage_(GRALLOC1_PRODUCER_USAGE_NONE), producer_usage_(GRALLOC1_PRODUCER_USAGE_NONE),
consumer_usage_(GRALLOC1_CONSUMER_USAGE_NONE) {} consumer_usage_(GRALLOC1_CONSUMER_USAGE_NONE),
id_(next_id_++) {}
BufferDescriptor(int w, int h, int f, gralloc1_producer_usage_t prod_usage, BufferDescriptor(int w, int h, int f, gralloc1_producer_usage_t prod_usage,
gralloc1_consumer_usage_t cons_usage) gralloc1_consumer_usage_t cons_usage)
@@ -51,9 +51,8 @@ class BufferDescriptor {
height_(h), height_(h),
format_(f), format_(f),
producer_usage_(prod_usage), producer_usage_(prod_usage),
consumer_usage_(cons_usage) {} consumer_usage_(cons_usage),
id_(next_id_++) {}
bool IsValid() { return (magic == kMagic); }
void SetConsumerUsage(gralloc1_consumer_usage_t usage) { consumer_usage_ = usage; } void SetConsumerUsage(gralloc1_consumer_usage_t usage) { consumer_usage_ = usage; }
@@ -76,15 +75,16 @@ class BufferDescriptor {
int GetFormat() const { return format_; } int GetFormat() const { return format_; }
private: gralloc1_buffer_descriptor_t GetId() const { return id_; }
static const int kMagic = 'gr1d';
int magic = kMagic; private:
int width_ = -1; int width_ = -1;
int height_ = -1; int height_ = -1;
int format_ = -1; int format_ = -1;
gralloc1_producer_usage_t producer_usage_ = GRALLOC1_PRODUCER_USAGE_NONE; gralloc1_producer_usage_t producer_usage_ = GRALLOC1_PRODUCER_USAGE_NONE;
gralloc1_consumer_usage_t consumer_usage_ = GRALLOC1_CONSUMER_USAGE_NONE; gralloc1_consumer_usage_t consumer_usage_ = GRALLOC1_CONSUMER_USAGE_NONE;
const gralloc1_buffer_descriptor_t id_;
static std::atomic<gralloc1_buffer_descriptor_t> next_id_;
}; };
}; // namespace gralloc1
#endif // __GR_BUF_DESCRIPTOR_H__ #endif // __GR_BUF_DESCRIPTOR_H__

View File

@@ -17,10 +17,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include <drm/drm_fourcc.h>
#include <drm_master.h>
#include <utility> #include <utility>
#include <vector>
#include "qd_utils.h" #include "qd_utils.h"
#include "gr_priv_handle.h" #include "gr_priv_handle.h"
@@ -30,194 +28,9 @@
#include "qdMetaData.h" #include "qdMetaData.h"
namespace gralloc1 { namespace gralloc1 {
std::atomic<gralloc1_buffer_descriptor_t> BufferDescriptor::next_id_(1);
using namespace drm_utils; BufferManager::BufferManager() : next_id_(0) {
static int getPlaneStrideOffset(private_handle_t *hnd, uint32_t *stride,
uint32_t *offset, uint32_t *num_planes) {
struct android_ycbcr yuvInfo = {};
*num_planes = 1;
switch (hnd->format) {
case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_BGR_565:
case HAL_PIXEL_FORMAT_RGBA_5551:
case HAL_PIXEL_FORMAT_RGBA_4444:
stride[0] = hnd->width * 2;
break;
case HAL_PIXEL_FORMAT_RGB_888:
stride[0] = hnd->width * 3;
break;
case HAL_PIXEL_FORMAT_RGBA_8888:
case HAL_PIXEL_FORMAT_BGRA_8888:
case HAL_PIXEL_FORMAT_RGBX_8888:
case HAL_PIXEL_FORMAT_BGRX_8888:
case HAL_PIXEL_FORMAT_RGBA_1010102:
case HAL_PIXEL_FORMAT_ARGB_2101010:
case HAL_PIXEL_FORMAT_RGBX_1010102:
case HAL_PIXEL_FORMAT_XRGB_2101010:
case HAL_PIXEL_FORMAT_BGRA_1010102:
case HAL_PIXEL_FORMAT_ABGR_2101010:
case HAL_PIXEL_FORMAT_BGRX_1010102:
case HAL_PIXEL_FORMAT_XBGR_2101010:
stride[0] = hnd->width * 4;
break;
}
// Format is RGB
if (stride[0]) {
return 0;
}
(*num_planes)++;
int ret = getYUVPlaneInfo(hnd, &yuvInfo);
if (ret < 0) {
ALOGE("%s failed", __FUNCTION__);
return ret;
}
stride[0] = static_cast<uint32_t>(yuvInfo.ystride);
offset[0] = static_cast<uint32_t>(
reinterpret_cast<uint64_t>(yuvInfo.y) - hnd->base);
stride[1] = static_cast<uint32_t>(yuvInfo.cstride);
switch (hnd->format) {
case HAL_PIXEL_FORMAT_YCbCr_420_SP:
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
case HAL_PIXEL_FORMAT_YCbCr_420_P010:
case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
offset[1] = static_cast<uint32_t>(
reinterpret_cast<uint64_t>(yuvInfo.cb) - hnd->base);
break;
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
case HAL_PIXEL_FORMAT_YCrCb_422_SP:
offset[1] = static_cast<uint32_t>(
reinterpret_cast<uint64_t>(yuvInfo.cr) - hnd->base);
break;
case HAL_PIXEL_FORMAT_YV12:
offset[1] = static_cast<uint32_t>(
reinterpret_cast<uint64_t>(yuvInfo.cr) - hnd->base);
stride[2] = static_cast<uint32_t>(yuvInfo.cstride);
offset[2] = static_cast<uint32_t>(
reinterpret_cast<uint64_t>(yuvInfo.cb) - hnd->base);
(*num_planes)++;
break;
default:
ALOGW("%s: Unsupported format %s", __FUNCTION__,
qdutils::GetHALPixelFormatString(hnd->format));
}
if (hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
std::fill(offset, offset + 4, 0);
}
return 0;
}
static void getDRMFormat(int hal_format, int flags, uint32_t *drm_format,
uint64_t *drm_format_modifier) {
if (flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
*drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
}
switch (hal_format) {
case HAL_PIXEL_FORMAT_RGBA_8888:
*drm_format = DRM_FORMAT_RGBA8888;
break;
case HAL_PIXEL_FORMAT_RGBA_5551:
*drm_format = DRM_FORMAT_RGBA5551;
break;
case HAL_PIXEL_FORMAT_RGBA_4444:
*drm_format = DRM_FORMAT_RGBA4444;
break;
case HAL_PIXEL_FORMAT_BGRA_8888:
*drm_format = DRM_FORMAT_BGRA8888;
break;
case HAL_PIXEL_FORMAT_RGBX_8888:
*drm_format = DRM_FORMAT_RGBX8888;
break;
case HAL_PIXEL_FORMAT_BGRX_8888:
*drm_format = DRM_FORMAT_BGRX8888;
break;
case HAL_PIXEL_FORMAT_RGB_888:
*drm_format = DRM_FORMAT_RGB888;
break;
case HAL_PIXEL_FORMAT_RGB_565:
*drm_format = DRM_FORMAT_RGB565;
break;
case HAL_PIXEL_FORMAT_BGR_565:
*drm_format = DRM_FORMAT_BGR565;
break;
case HAL_PIXEL_FORMAT_RGBA_1010102:
*drm_format = DRM_FORMAT_RGBA1010102;
break;
case HAL_PIXEL_FORMAT_ARGB_2101010:
*drm_format = DRM_FORMAT_ARGB2101010;
break;
case HAL_PIXEL_FORMAT_RGBX_1010102:
*drm_format = DRM_FORMAT_RGBX1010102;
break;
case HAL_PIXEL_FORMAT_XRGB_2101010:
*drm_format = DRM_FORMAT_XRGB2101010;
break;
case HAL_PIXEL_FORMAT_BGRA_1010102:
*drm_format = DRM_FORMAT_BGRA1010102;
break;
case HAL_PIXEL_FORMAT_ABGR_2101010:
*drm_format = DRM_FORMAT_ABGR2101010;
break;
case HAL_PIXEL_FORMAT_BGRX_1010102:
*drm_format = DRM_FORMAT_BGRX1010102;
break;
case HAL_PIXEL_FORMAT_XBGR_2101010:
*drm_format = DRM_FORMAT_XBGR2101010;
break;
case HAL_PIXEL_FORMAT_YCbCr_420_SP:
*drm_format = DRM_FORMAT_NV12;
break;
case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
*drm_format = DRM_FORMAT_NV12;
break;
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
*drm_format = DRM_FORMAT_NV12;
*drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
break;
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
*drm_format = DRM_FORMAT_NV21;
break;
case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
*drm_format = DRM_FORMAT_NV21;
break;
case HAL_PIXEL_FORMAT_YCbCr_420_P010:
// TODO *drm_format = DRM_FORMAT_P010;
break;
case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
// TODO *drm_format = DRM_FORMAT_P010;
// *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED |
// DRM_FORMAT_MOD_QCOM_TIGHT;
break;
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
*drm_format = DRM_FORMAT_NV16;
break;
case HAL_PIXEL_FORMAT_YCrCb_422_SP:
*drm_format = DRM_FORMAT_NV61;
break;
case HAL_PIXEL_FORMAT_YV12:
*drm_format = DRM_FORMAT_YVU420;
break;
default:
ALOGW("%s: Unsupported format %s", __FUNCTION__,
qdutils::GetHALPixelFormatString(hal_format));
}
}
BufferManager::BufferManager() {
char property[PROPERTY_VALUE_MAX]; char property[PROPERTY_VALUE_MAX];
// Map framebuffer memory // Map framebuffer memory
@@ -235,6 +48,29 @@ BufferManager::BufferManager() {
} }
handles_map_.clear(); handles_map_.clear();
allocator_ = new Allocator();
allocator_->Init();
}
gralloc1_error_t BufferManager::CreateBufferDescriptor(
gralloc1_buffer_descriptor_t *descriptor_id) {
std::lock_guard<std::mutex> lock(locker_);
auto descriptor = std::make_shared<BufferDescriptor>();
descriptors_map_.emplace(descriptor->GetId(), descriptor);
*descriptor_id = descriptor->GetId();
return GRALLOC1_ERROR_NONE;
}
gralloc1_error_t BufferManager::DestroyBufferDescriptor(
gralloc1_buffer_descriptor_t descriptor_id) {
std::lock_guard<std::mutex> lock(locker_);
const auto descriptor = descriptors_map_.find(descriptor_id);
if (descriptor == descriptors_map_.end()) {
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
}
descriptors_map_.erase(descriptor);
return GRALLOC1_ERROR_NONE;
} }
BufferManager::~BufferManager() { BufferManager::~BufferManager() {
@@ -243,14 +79,8 @@ BufferManager::~BufferManager() {
} }
} }
bool BufferManager::Init() {
allocator_ = new Allocator();
return allocator_->Init();
}
gralloc1_error_t BufferManager::AllocateBuffers(uint32_t num_descriptors, gralloc1_error_t BufferManager::AllocateBuffers(uint32_t num_descriptors,
const BufferDescriptor *descriptors, const gralloc1_buffer_descriptor_t *descriptor_ids,
buffer_handle_t *out_buffers) { buffer_handle_t *out_buffers) {
bool shared = true; bool shared = true;
gralloc1_error_t status = GRALLOC1_ERROR_NONE; gralloc1_error_t status = GRALLOC1_ERROR_NONE;
@@ -259,10 +89,28 @@ gralloc1_error_t BufferManager::AllocateBuffers(uint32_t num_descriptors,
// client can ask to test the allocation by passing NULL out_buffers // client can ask to test the allocation by passing NULL out_buffers
bool test_allocate = !out_buffers; bool test_allocate = !out_buffers;
// Validate descriptors
std::vector<std::shared_ptr<BufferDescriptor>> descriptors;
for (uint32_t i = 0; i < num_descriptors; i++) {
const auto map_descriptor = descriptors_map_.find(descriptor_ids[i]);
if (map_descriptor == descriptors_map_.end()) {
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
} else {
descriptors.push_back(map_descriptor->second);
}
}
// Resolve implementation defined formats
for (auto &descriptor : descriptors) {
descriptor->SetColorFormat(allocator_->GetImplDefinedFormat(descriptor->GetProducerUsage(),
descriptor->GetConsumerUsage(),
descriptor->GetFormat()));
}
// Check if input descriptors can be supported AND // Check if input descriptors can be supported AND
// Find out if a single buffer can be shared for all the given input descriptors // Find out if a single buffer can be shared for all the given input descriptors
uint32_t i = 0; uint32_t i = 0;
int max_buf_index = -1; ssize_t max_buf_index = -1;
shared = allocator_->CheckForBufferSharing(num_descriptors, descriptors, &max_buf_index); shared = allocator_->CheckForBufferSharing(num_descriptors, descriptors, &max_buf_index);
if (test_allocate) { if (test_allocate) {
@@ -272,7 +120,7 @@ gralloc1_error_t BufferManager::AllocateBuffers(uint32_t num_descriptors,
if (shared && (max_buf_index >= 0)) { if (shared && (max_buf_index >= 0)) {
// Allocate one and duplicate/copy the handles for each descriptor // Allocate one and duplicate/copy the handles for each descriptor
if (AllocateBuffer(descriptors[max_buf_index], &out_buffers[max_buf_index])) { if (AllocateBuffer(*descriptors[UINT(max_buf_index)], &out_buffers[max_buf_index])) {
return GRALLOC1_ERROR_NO_RESOURCES; return GRALLOC1_ERROR_NO_RESOURCES;
} }
@@ -281,20 +129,14 @@ gralloc1_error_t BufferManager::AllocateBuffers(uint32_t num_descriptors,
// Current assumption is even MetaData memory would be same // Current assumption is even MetaData memory would be same
// Need to revisit if there is a need for own metadata memory // Need to revisit if there is a need for own metadata memory
if (i != UINT(max_buf_index)) { if (i != UINT(max_buf_index)) {
CreateSharedHandle(out_buffers[max_buf_index], descriptors[i], &out_buffers[i]); CreateSharedHandle(out_buffers[max_buf_index], *descriptors[i], &out_buffers[i]);
// since we just created handle out of existing handle add it to map
locker_.lock();
handles_map_.insert(std::pair<private_handle_t const *, int>(
reinterpret_cast<private_handle_t const *>(out_buffers[i]), 1));
locker_.unlock();
} }
} }
} else { } else {
// Buffer sharing is not feasible. // Buffer sharing is not feasible.
// Allocate seperate buffer for each descriptor // Allocate separate buffer for each descriptor
for (i = 0; i < num_descriptors; i++) { for (i = 0; i < num_descriptors; i++) {
if (AllocateBuffer(descriptors[i], &out_buffers[i])) { if (AllocateBuffer(*descriptors[i], &out_buffers[i])) {
return GRALLOC1_ERROR_NO_RESOURCES; return GRALLOC1_ERROR_NO_RESOURCES;
} }
} }
@@ -322,46 +164,41 @@ void BufferManager::CreateSharedHandle(buffer_handle_t inbuffer, const BufferDes
int buffer_type = GetBufferType(descriptor.GetFormat()); int buffer_type = GetBufferType(descriptor.GetFormat());
// Duplicate the fds // Duplicate the fds
private_handle_t *out_hnd = new private_handle_t(
dup(input->fd), input->size, flags, buffer_type, descriptor.GetFormat(), INT(alignedw),
INT(alignedh), dup(input->fd_metadata), input->offset_metadata, input->base_metadata,
descriptor.GetWidth(), descriptor.GetHeight(), descriptor.GetProducerUsage(),
descriptor.GetConsumerUsage());
// TODO(user): Not sure what to do for fb_id. Use duped fd and new dimensions? // TODO(user): Not sure what to do for fb_id. Use duped fd and new dimensions?
private_handle_t *out_hnd = new private_handle_t(dup(input->fd),
dup(input->fd_metadata),
flags,
INT(alignedw),
INT(alignedh),
descriptor.GetWidth(),
descriptor.GetHeight(),
descriptor.GetFormat(),
buffer_type,
input->size,
descriptor.GetProducerUsage(),
descriptor.GetConsumerUsage());
out_hnd->id = ++next_id_;
// TODO(user): Base address of shared handle and ion handles
auto buffer = std::make_shared<Buffer>(out_hnd);
handles_map_.emplace(std::make_pair(out_hnd->id, buffer));
*outbuffer = out_hnd; *outbuffer = out_hnd;
} }
gralloc1_error_t BufferManager::FreeBuffer(private_handle_t const *hnd) { gralloc1_error_t BufferManager::FreeBuffer(std::shared_ptr<Buffer> buf) {
auto hnd = buf->handle;
if (allocator_->FreeBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset, if (allocator_->FreeBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset,
hnd->fd) != 0) { hnd->fd, buf->ion_handle_main) != 0) {
return GRALLOC1_ERROR_BAD_HANDLE; return GRALLOC1_ERROR_BAD_HANDLE;
} }
unsigned int meta_size = ALIGN((unsigned int)sizeof(MetaData_t), PAGE_SIZE); unsigned int meta_size = ALIGN((unsigned int)sizeof(MetaData_t), PAGE_SIZE);
if (allocator_->FreeBuffer(reinterpret_cast<void *>(hnd->base_metadata), meta_size, if (allocator_->FreeBuffer(reinterpret_cast<void *>(hnd->base_metadata), meta_size,
hnd->offset_metadata, hnd->fd_metadata) != 0) { hnd->offset_metadata, hnd->fd_metadata, buf->ion_handle_meta) != 0) {
return GRALLOC1_ERROR_BAD_HANDLE; return GRALLOC1_ERROR_BAD_HANDLE;
} }
// delete handle also // TODO(user): delete handle once framework bug around this is confirmed
private_handle_t *handle = const_cast<private_handle_t *>(hnd); // to be resolved
if (handle->fb_id) {
int ret = DRMMaster::GetInstance(&master);
if (ret < 0) {
ALOGE("%s Failed to acquire DRMMaster instance", __FUNCTION__);
return ret;
}
ret = master->RemoveFbId(hnd->gem_handle, hnd->fb_id);
if (ret < 0) {
ALOGE("%s: Removing fb_id %d failed with error %d", __FUNCTION__,
hnd->fb_id, errno);
}
}
delete handle;
return GRALLOC1_ERROR_NONE; return GRALLOC1_ERROR_NONE;
} }
@@ -385,44 +222,42 @@ gralloc1_error_t BufferManager::MapBuffer(private_handle_t const *handle) {
} }
gralloc1_error_t BufferManager::RetainBuffer(private_handle_t const *hnd) { gralloc1_error_t BufferManager::RetainBuffer(private_handle_t const *hnd) {
locker_.lock(); std::lock_guard<std::mutex> lock(locker_);
// find if this handle is already in map // find if this handle is already in map
auto it = handles_map_.find(hnd); auto it = handles_map_.find(hnd->id);
if (it != handles_map_.end()) { if (it != handles_map_.end()) {
// It's already in map, Just increment refcnt // It's already in map, Just increment refcnt
// No need to mmap the memory. // No need to mmap the memory.
it->second = it->second + 1; auto buf = it->second;
buf->ref_count++;
} else { } else {
// not present in the map. mmap and then add entry to map // not present in the map. mmap and then add entry to map
if (MapBuffer(hnd) == GRALLOC1_ERROR_NONE) { if (MapBuffer(hnd) == GRALLOC1_ERROR_NONE) {
handles_map_.insert(std::pair<private_handle_t const *, int>(hnd, 1)); auto buffer = std::make_shared<Buffer>(hnd);
handles_map_.emplace(std::make_pair(hnd->id, buffer));
} }
} }
locker_.unlock();
return GRALLOC1_ERROR_NONE; return GRALLOC1_ERROR_NONE;
} }
gralloc1_error_t BufferManager::ReleaseBuffer(private_handle_t const *hnd) { gralloc1_error_t BufferManager::ReleaseBuffer(private_handle_t const *hnd) {
locker_.lock(); std::lock_guard<std::mutex> lock(locker_);
// find if this handle is already in map // find if this handle is already in map
auto it = handles_map_.find(hnd); auto it = handles_map_.find(hnd->id);
if (it == handles_map_.end()) { if (it == handles_map_.end()) {
// Corrupt handle or map. // Corrupt handle or map.
locker_.unlock(); ALOGE("Could not find handle");
return GRALLOC1_ERROR_BAD_HANDLE; return GRALLOC1_ERROR_BAD_HANDLE;
} else { } else {
it->second = it->second - 1; auto buf = it->second;
} buf->ref_count--;
if (buf->ref_count == 0) {
if (!it->second) {
handles_map_.erase(it); handles_map_.erase(it);
FreeBuffer(hnd); FreeBuffer(buf);
}
} }
locker_.unlock();
return GRALLOC1_ERROR_NONE; return GRALLOC1_ERROR_NONE;
} }
@@ -481,9 +316,9 @@ gralloc1_error_t BufferManager::UnlockBuffer(const private_handle_t *handle) {
return status; return status;
} }
int BufferManager::GetDataAlignment(int format, gralloc1_producer_usage_t prod_usage, uint32_t BufferManager::GetDataAlignment(int format, gralloc1_producer_usage_t prod_usage,
gralloc1_consumer_usage_t cons_usage) { gralloc1_consumer_usage_t cons_usage) {
int align = getpagesize(); uint32_t align = UINT(getpagesize());
if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) { if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) {
align = 8192; align = 8192;
} }
@@ -566,94 +401,61 @@ int BufferManager::AllocateBuffer(unsigned int size, int aligned_w, int aligned_
int unaligned_h, int format, int bufferType, int unaligned_h, int format, int bufferType,
gralloc1_producer_usage_t prod_usage, gralloc1_producer_usage_t prod_usage,
gralloc1_consumer_usage_t cons_usage, buffer_handle_t *handle) { gralloc1_consumer_usage_t cons_usage, buffer_handle_t *handle) {
auto page_size = UINT(getpagesize());
int err = 0; int err = 0;
int flags = 0; int flags = 0;
size = ALIGN(size, PAGE_SIZE);
AllocData data; AllocData data;
data.align = (unsigned int)GetDataAlignment(format, prod_usage, cons_usage); data.align = GetDataAlignment(format, prod_usage, cons_usage);
size = ALIGN(size, data.align); data.size = ALIGN(size, data.align);
data.size = size;
data.handle = (uintptr_t)handle; data.handle = (uintptr_t)handle;
// Allocate memory
data.uncached = allocator_->UseUncached(prod_usage); data.uncached = allocator_->UseUncached(prod_usage);
// Allocate buffer memory
err = allocator_->AllocateMem(&data, prod_usage, cons_usage); err = allocator_->AllocateMem(&data, prod_usage, cons_usage);
if (err) { if (err) {
ALOGE("gralloc failed to allocate err=%s", strerror(-err)); ALOGE("gralloc failed to allocate err=%s", strerror(-err));
*handle = 0;
return err; return err;
} }
// allocate memory for MetaData // Allocate memory for MetaData
AllocData e_data; AllocData e_data;
e_data.size = ALIGN((unsigned int)sizeof(MetaData_t), PAGE_SIZE); e_data.size = ALIGN(UINT(sizeof(MetaData_t)), page_size);
e_data.handle = data.handle; e_data.handle = data.handle;
e_data.align = (unsigned int)getpagesize(); e_data.align = page_size;
ColorSpace_t colorSpace = ITU_R_601;
if (prod_usage & GRALLOC1_PRODUCER_USAGE_CAMERA) {
colorSpace = ITU_R_601_FR;
}
err = err =
allocator_->AllocateMem(&e_data, GRALLOC1_PRODUCER_USAGE_NONE, GRALLOC1_CONSUMER_USAGE_NONE); allocator_->AllocateMem(&e_data, GRALLOC1_PRODUCER_USAGE_NONE, GRALLOC1_CONSUMER_USAGE_NONE);
ALOGE_IF(err, "gralloc failed for e_daata error=%s", strerror(-err)); if (err) {
ALOGE("gralloc failed to allocate metadata error=%s", strerror(-err));
return err;
}
flags = GetHandleFlags(format, prod_usage, cons_usage); flags = GetHandleFlags(format, prod_usage, cons_usage);
flags |= data.alloc_type; flags |= data.alloc_type;
// Create handle // Create handle
uint64_t eBaseAddr = (uint64_t)(e_data.base) + e_data.offset; private_handle_t *hnd = new private_handle_t(data.fd,
private_handle_t *hnd = new private_handle_t(data.fd, size, flags, bufferType, format, aligned_w, e_data.fd,
aligned_h, e_data.fd, e_data.offset, eBaseAddr, flags,
unaligned_w, unaligned_h, prod_usage, cons_usage); aligned_w,
aligned_h,
unaligned_w,
unaligned_h,
format,
bufferType,
size,
prod_usage,
cons_usage);
hnd->offset = data.offset; hnd->id = ++next_id_;
hnd->base = (uint64_t)(data.base) + data.offset; hnd->base = reinterpret_cast<uint64_t >(data.base);
hnd->gpuaddr = 0; hnd->base_metadata = reinterpret_cast<uint64_t >(e_data.base);
ColorSpace_t colorSpace = ITU_R_601;
setMetaData(hnd, UPDATE_COLOR_SPACE, reinterpret_cast<void *>(&colorSpace)); setMetaData(hnd, UPDATE_COLOR_SPACE, reinterpret_cast<void *>(&colorSpace));
if (qdutils::getDriverType() == qdutils::DriverType::DRM &&
cons_usage & GRALLOC_USAGE_HW_COMPOSER) {
DRMBuffer buf = {};
int ret = getPlaneStrideOffset(hnd, buf.stride, buf.offset,
&buf.num_planes);
if (ret < 0) {
ALOGE("%s failed", __FUNCTION__);
return ret;
}
buf.fd = hnd->fd;
buf.width = hnd->width;
buf.height = hnd->height;
getDRMFormat(hnd->format, flags, &buf.drm_format,
&buf.drm_format_modifier);
DRMMaster *master = nullptr;
ret = DRMMaster::GetInstance(&master);
if (ret < 0) {
ALOGE("%s Failed to acquire DRMMaster instance", __FUNCTION__);
return ret;
}
ret = master->CreateFbId(buf, &hnd->gem_handle, &hnd->fb_id);
if (ret < 0) {
ALOGE("%s: CreateFbId failed. width %d, height %d, " \
"format: %s, stride %u, error %d", __FUNCTION__,
buf.width, buf.height,
qdutils::GetHALPixelFormatString(hnd->format),
buf.stride[0], errno);
return ret;
}
}
*handle = hnd; *handle = hnd;
auto buffer = std::make_shared<Buffer>(hnd, data.ion_handle, e_data.ion_handle);
// we have just allocated the buffer & mmapped. Add to map handles_map_.emplace(std::make_pair(hnd->id, buffer));
locker_.lock();
handles_map_.insert(std::pair<private_handle_t const *, int>(hnd, 1));
locker_.unlock();
return err; return err;
} }
@@ -739,8 +541,8 @@ gralloc1_error_t BufferManager::Perform(int operation, va_list args) {
allocator_->GetAlignedWidthAndHeight(descriptor, &alignedw, &alignedh); allocator_->GetAlignedWidthAndHeight(descriptor, &alignedw, &alignedh);
hnd->unaligned_width = width; hnd->unaligned_width = width;
hnd->unaligned_height = height; hnd->unaligned_height = height;
hnd->width = alignedw; hnd->width = INT(alignedw);
hnd->height = alignedh; hnd->height = INT(alignedh);
hnd->format = format; hnd->format = format;
*handle = reinterpret_cast<native_handle_t *>(hnd); *handle = reinterpret_cast<native_handle_t *>(hnd);
} }
@@ -889,11 +691,116 @@ gralloc1_error_t BufferManager::Perform(int operation, va_list args) {
} }
} break; } break;
case GRALLOC1_MODULE_PERFORM_GET_BUFFER_SIZE_AND_DIMENSIONS: {
int width = va_arg(args, int);
int height = va_arg(args, int);
int format = va_arg(args, int);
uint64_t p_usage = va_arg(args, uint64_t);
uint64_t c_usage = va_arg(args, uint64_t);
gralloc1_producer_usage_t producer_usage = static_cast<gralloc1_producer_usage_t>(p_usage);
gralloc1_consumer_usage_t consumer_usage = static_cast<gralloc1_consumer_usage_t>(c_usage);
uint32_t *aligned_width = va_arg(args, uint32_t *);
uint32_t *aligned_height = va_arg(args, uint32_t *);
uint32_t *size = va_arg(args, uint32_t *);
auto descriptor = BufferDescriptor(width, height, format, producer_usage, consumer_usage);
allocator_->GetBufferSizeAndDimensions(descriptor, size, aligned_width, aligned_height);
// Align size
auto align = GetDataAlignment(format, producer_usage, consumer_usage);
*size = ALIGN(*size, align);
} break;
// TODO(user): Break out similar functionality, preferably moving to a common lib.
case GRALLOC1_MODULE_PERFORM_ALLOCATE_BUFFER: {
int width = va_arg(args, int);
int height = va_arg(args, int);
int format = va_arg(args, int);
uint64_t p_usage = va_arg(args, uint64_t);
uint64_t c_usage = va_arg(args, uint64_t);
buffer_handle_t *hnd = va_arg(args, buffer_handle_t*);
gralloc1_producer_usage_t producer_usage = static_cast<gralloc1_producer_usage_t>(p_usage);
gralloc1_consumer_usage_t consumer_usage = static_cast<gralloc1_consumer_usage_t>(c_usage);
BufferDescriptor descriptor(width, height, format, producer_usage, consumer_usage);
unsigned int size;
unsigned int alignedw, alignedh;
allocator_->GetBufferSizeAndDimensions(descriptor, &size, &alignedw, &alignedh);
AllocateBuffer(descriptor, hnd, size);
} break;
default: default:
break; break;
} }
return GRALLOC1_ERROR_NONE; return GRALLOC1_ERROR_NONE;
} }
static bool IsYuvFormat(const private_handle_t *hnd) {
switch (hnd->format) {
case HAL_PIXEL_FORMAT_YCbCr_420_SP:
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: // Same as YCbCr_420_SP_VENUS
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_YCrCb_422_SP:
case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
case HAL_PIXEL_FORMAT_NV21_ZSL:
case HAL_PIXEL_FORMAT_RAW16:
case HAL_PIXEL_FORMAT_RAW10:
case HAL_PIXEL_FORMAT_YV12:
return true;
default:
return false;
}
}
gralloc1_error_t BufferManager::GetNumFlexPlanes(const private_handle_t *hnd,
uint32_t *out_num_planes) {
if (!IsYuvFormat(hnd)) {
return GRALLOC1_ERROR_UNSUPPORTED;
} else {
*out_num_planes = 3;
}
return GRALLOC1_ERROR_NONE;
}
gralloc1_error_t BufferManager::GetFlexLayout(const private_handle_t *hnd,
struct android_flex_layout *layout) {
if (!IsYuvFormat(hnd)) {
return GRALLOC1_ERROR_UNSUPPORTED;
}
android_ycbcr ycbcr;
int err = allocator_->GetYUVPlaneInfo(hnd, &ycbcr);
if (err != 0) {
return GRALLOC1_ERROR_BAD_HANDLE;
}
layout->format = FLEX_FORMAT_YCbCr;
layout->num_planes = 3;
for (uint32_t i = 0; i < layout->num_planes; i++) {
layout->planes[i].bits_per_component = 8;
layout->planes[i].bits_used = 8;
layout->planes[i].h_increment = 1;
layout->planes[i].v_increment = 1;
layout->planes[i].h_subsampling = 2;
layout->planes[i].v_subsampling = 2;
}
layout->planes[0].top_left = static_cast<uint8_t *>(ycbcr.y);
layout->planes[0].component = FLEX_COMPONENT_Y;
layout->planes[0].v_increment = static_cast<int32_t>(ycbcr.ystride);
layout->planes[1].top_left = static_cast<uint8_t *>(ycbcr.cb);
layout->planes[1].component = FLEX_COMPONENT_Cb;
layout->planes[1].h_increment = static_cast<int32_t>(ycbcr.chroma_step);
layout->planes[1].v_increment = static_cast<int32_t>(ycbcr.cstride);
layout->planes[2].top_left = static_cast<uint8_t *>(ycbcr.cr);
layout->planes[2].component = FLEX_COMPONENT_Cr;
layout->planes[2].h_increment = static_cast<int32_t>(ycbcr.chroma_step);
layout->planes[2].v_increment = static_cast<int32_t>(ycbcr.cstride);
return GRALLOC1_ERROR_NONE;
}
} // namespace gralloc1 } // namespace gralloc1

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011-2016, The Linux Foundation. All rights reserved. * Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
* Not a Contribution * Not a Contribution
* *
* Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
@@ -22,30 +22,55 @@
#include <pthread.h> #include <pthread.h>
#include <unordered_map> #include <unordered_map>
#include <unordered_set>
#include <utility>
#include <mutex> #include <mutex>
#include "gralloc_priv.h" #include "gralloc_priv.h"
#include "gr_allocator.h" #include "gr_allocator.h"
#include "gr_buf_descriptor.h"
namespace gralloc1 { namespace gralloc1 {
class BufferManager { class BufferManager {
public: public:
BufferManager();
~BufferManager(); ~BufferManager();
bool Init(); gralloc1_error_t CreateBufferDescriptor(gralloc1_buffer_descriptor_t *descriptor_id);
gralloc1_error_t AllocateBuffers(uint32_t numDescriptors, const BufferDescriptor *descriptors, gralloc1_error_t DestroyBufferDescriptor(gralloc1_buffer_descriptor_t descriptor_id);
buffer_handle_t *outBuffers); gralloc1_error_t AllocateBuffers(uint32_t num_descriptors,
const gralloc1_buffer_descriptor_t *descriptor_ids,
buffer_handle_t *out_buffers);
gralloc1_error_t RetainBuffer(private_handle_t const *hnd); gralloc1_error_t RetainBuffer(private_handle_t const *hnd);
gralloc1_error_t ReleaseBuffer(private_handle_t const *hnd); gralloc1_error_t ReleaseBuffer(private_handle_t const *hnd);
gralloc1_error_t LockBuffer(const private_handle_t *hnd, gralloc1_producer_usage_t prod_usage, gralloc1_error_t LockBuffer(const private_handle_t *hnd, gralloc1_producer_usage_t prod_usage,
gralloc1_consumer_usage_t cons_usage); gralloc1_consumer_usage_t cons_usage);
gralloc1_error_t UnlockBuffer(const private_handle_t *hnd); gralloc1_error_t UnlockBuffer(const private_handle_t *hnd);
gralloc1_error_t Perform(int operation, va_list args); gralloc1_error_t Perform(int operation, va_list args);
gralloc1_error_t GetFlexLayout(const private_handle_t *hnd, struct android_flex_layout *layout);
gralloc1_error_t GetNumFlexPlanes(const private_handle_t *hnd, uint32_t *out_num_planes);
template <typename... Args>
gralloc1_error_t CallBufferDescriptorFunction(gralloc1_buffer_descriptor_t descriptor_id,
void (BufferDescriptor::*member)(Args...),
Args... args) {
std::lock_guard<std::mutex> lock(locker_);
const auto map_descriptor = descriptors_map_.find(descriptor_id);
if (map_descriptor == descriptors_map_.end()) {
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
}
const auto descriptor = map_descriptor->second;
(descriptor.get()->*member)(std::forward<Args>(args)...);
return GRALLOC1_ERROR_NONE;
}
static BufferManager* GetInstance() {
static BufferManager *instance = new BufferManager();
return instance;
}
private: private:
BufferManager();
gralloc1_error_t MapBuffer(private_handle_t const *hnd); gralloc1_error_t MapBuffer(private_handle_t const *hnd);
gralloc1_error_t FreeBuffer(private_handle_t const *hnd);
int GetBufferType(int format); int GetBufferType(int format);
int AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle, int AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle,
unsigned int bufferSize = 0); unsigned int bufferSize = 0);
@@ -53,18 +78,44 @@ class BufferManager {
int unaligned_h, int format, int bufferType, int unaligned_h, int format, int bufferType,
gralloc1_producer_usage_t prod_usage, gralloc1_consumer_usage_t cons_usage, gralloc1_producer_usage_t prod_usage, gralloc1_consumer_usage_t cons_usage,
buffer_handle_t *handle); buffer_handle_t *handle);
int GetDataAlignment(int format, gralloc1_producer_usage_t prod_usage, uint32_t GetDataAlignment(int format, gralloc1_producer_usage_t prod_usage,
gralloc1_consumer_usage_t cons_usage); gralloc1_consumer_usage_t cons_usage);
int GetHandleFlags(int format, gralloc1_producer_usage_t prod_usage, int GetHandleFlags(int format, gralloc1_producer_usage_t prod_usage,
gralloc1_consumer_usage_t cons_usage); gralloc1_consumer_usage_t cons_usage);
void CreateSharedHandle(buffer_handle_t inbuffer, const BufferDescriptor &descriptor, void CreateSharedHandle(buffer_handle_t inbuffer, const BufferDescriptor &descriptor,
buffer_handle_t *out_buffer); buffer_handle_t *out_buffer);
// Wrapper structure over private handle
// Values associated with the private handle
// that do not need to go over IPC can be placed here
// This structure is also not expected to be ABI stable
// unlike private_handle_t
struct Buffer {
const private_handle_t *handle = nullptr;
int ref_count = 1;
// Hold the main and metadata ion handles
// Freed from the allocator process
// and unused in the mapping process
int ion_handle_main = -1;
int ion_handle_meta = -1;
Buffer() = delete;
explicit Buffer(const private_handle_t* h, int ih_main = -1, int ih_meta = -1):
handle(h),
ion_handle_main(ih_main),
ion_handle_meta(ih_meta) {
}
};
gralloc1_error_t FreeBuffer(std::shared_ptr<Buffer> buf);
bool map_fb_mem_ = false; bool map_fb_mem_ = false;
bool ubwc_for_fb_ = false; bool ubwc_for_fb_ = false;
Allocator *allocator_ = NULL; Allocator *allocator_ = NULL;
std::mutex locker_; std::mutex locker_;
std::unordered_map<private_handle_t const *, int> handles_map_ = {}; std::unordered_map<uint64_t, std::shared_ptr<Buffer>> handles_map_ = {};
std::unordered_map<gralloc1_buffer_descriptor_t,
std::shared_ptr<BufferDescriptor>> descriptors_map_ = {};
std::atomic<uint64_t> next_id_;
}; };
} // namespace gralloc1 } // namespace gralloc1

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, The Linux Foundation. All rights reserved. * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
@@ -29,6 +29,8 @@
#include <cutils/log.h> #include <cutils/log.h>
#include <sync/sync.h> #include <sync/sync.h>
#include <sstream>
#include <string>
#include "gr_device_impl.h" #include "gr_device_impl.h"
#include "gr_buf_descriptor.h" #include "gr_buf_descriptor.h"
@@ -43,13 +45,11 @@ int gralloc_device_close(struct hw_device_t *device);
static struct hw_module_methods_t gralloc_module_methods = {.open = gralloc_device_open}; static struct hw_module_methods_t gralloc_module_methods = {.open = gralloc_device_open};
struct hw_module_t gralloc_module = {}; struct gralloc_module_t HAL_MODULE_INFO_SYM = {
.common = {
struct private_module_t HAL_MODULE_INFO_SYM = {
.base = {
.tag = HARDWARE_MODULE_TAG, .tag = HARDWARE_MODULE_TAG,
.version_major = 1, .module_api_version = GRALLOC_MODULE_API_VERSION_1_0,
.version_minor = 0, .hal_api_version = HARDWARE_HAL_API_VERSION,
.id = GRALLOC_HARDWARE_MODULE_ID, .id = GRALLOC_HARDWARE_MODULE_ID,
.name = "Graphics Memory Module", .name = "Graphics Memory Module",
.author = "Code Aurora Forum", .author = "Code Aurora Forum",
@@ -62,42 +62,34 @@ struct private_module_t HAL_MODULE_INFO_SYM = {
int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device) { int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device) {
int status = -EINVAL; int status = -EINVAL;
if (!strcmp(name, GRALLOC_HARDWARE_MODULE_ID)) { if (!strcmp(name, GRALLOC_HARDWARE_MODULE_ID)) {
const private_module_t *m = reinterpret_cast<const private_module_t *>(module); gralloc1::GrallocImpl * /*gralloc1_device_t*/ dev = gralloc1::GrallocImpl::GetInstance(module);
gralloc1::GrallocImpl * /*gralloc1_device_t*/ dev = new gralloc1::GrallocImpl(m);
*device = reinterpret_cast<hw_device_t *>(dev); *device = reinterpret_cast<hw_device_t *>(dev);
if (dev->Init()) { if (dev->Init()) {
status = 0; status = 0;
} else { } else {
ALOGE(" Error in opening gralloc1 device"); ALOGE(" Error in opening gralloc1 device");
return status;
} }
} }
return status; return status;
} }
namespace gralloc1 { namespace gralloc1 {
GrallocImpl::GrallocImpl(const private_module_t *module) { GrallocImpl::GrallocImpl(const hw_module_t *module) {
common.tag = HARDWARE_DEVICE_TAG; common.tag = HARDWARE_DEVICE_TAG;
common.version = 1; // TODO(user): cross check version common.version = GRALLOC_MODULE_API_VERSION_1_0;
common.module = const_cast<hw_module_t *>(&module->base); common.module = const_cast<hw_module_t *>(module);
common.close = CloseDevice; common.close = CloseDevice;
getFunction = GetFunction; getFunction = GetFunction;
getCapabilities = GetCapabilities; getCapabilities = GetCapabilities;
} }
bool GrallocImpl::Init() { bool GrallocImpl::Init() {
buf_mgr_ = new BufferManager(); buf_mgr_ = BufferManager::GetInstance();
return true;
return buf_mgr_->Init();
} }
GrallocImpl::~GrallocImpl() { GrallocImpl::~GrallocImpl() {
if (buf_mgr_) {
delete buf_mgr_;
}
} }
int GrallocImpl::CloseDevice(hw_device_t *device) { int GrallocImpl::CloseDevice(hw_device_t *device) {
@@ -127,6 +119,8 @@ gralloc1_function_pointer_t GrallocImpl::GetFunction(gralloc1_device_t *device,
} }
switch (function) { switch (function) {
case GRALLOC1_FUNCTION_DUMP:
return reinterpret_cast<gralloc1_function_pointer_t>(Dump);
case GRALLOC1_FUNCTION_CREATE_DESCRIPTOR: case GRALLOC1_FUNCTION_CREATE_DESCRIPTOR:
return reinterpret_cast<gralloc1_function_pointer_t>(CreateBufferDescriptor); return reinterpret_cast<gralloc1_function_pointer_t>(CreateBufferDescriptor);
case GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR: case GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR:
@@ -157,17 +151,12 @@ gralloc1_function_pointer_t GrallocImpl::GetFunction(gralloc1_device_t *device,
return reinterpret_cast<gralloc1_function_pointer_t>(RetainBuffer); return reinterpret_cast<gralloc1_function_pointer_t>(RetainBuffer);
case GRALLOC1_FUNCTION_RELEASE: case GRALLOC1_FUNCTION_RELEASE:
return reinterpret_cast<gralloc1_function_pointer_t>(ReleaseBuffer); return reinterpret_cast<gralloc1_function_pointer_t>(ReleaseBuffer);
/* TODO(user) :definition of flex plane is not known yet case GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES:
* Need to implement after clarification from Google. return reinterpret_cast<gralloc1_function_pointer_t>(GetNumFlexPlanes);
* case GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES:
return reinterpret_cast<gralloc1_function_pointer_t> (; */
case GRALLOC1_FUNCTION_LOCK: case GRALLOC1_FUNCTION_LOCK:
return reinterpret_cast<gralloc1_function_pointer_t>(LockBuffer); return reinterpret_cast<gralloc1_function_pointer_t>(LockBuffer);
/* TODO(user) : LOCK_YCBCR changed to LOCK_FLEX but structure is not known yet. case GRALLOC1_FUNCTION_LOCK_FLEX:
* Need to implement after clarification from Google. return reinterpret_cast<gralloc1_function_pointer_t>(LockFlex);
case GRALLOC1_PFN_LOCK_FLEX:
return reinterpret_cast<gralloc1_function_pointer_t> (LockYCbCrBuffer;
*/
case GRALLOC1_FUNCTION_UNLOCK: case GRALLOC1_FUNCTION_UNLOCK:
return reinterpret_cast<gralloc1_function_pointer_t>(UnlockBuffer); return reinterpret_cast<gralloc1_function_pointer_t>(UnlockBuffer);
case GRALLOC1_FUNCTION_PERFORM: case GRALLOC1_FUNCTION_PERFORM:
@@ -180,12 +169,24 @@ gralloc1_function_pointer_t GrallocImpl::GetFunction(gralloc1_device_t *device,
return NULL; return NULL;
} }
gralloc1_error_t GrallocImpl::CheckDeviceAndDescriptor(gralloc1_device_t *device, gralloc1_error_t GrallocImpl::Dump(gralloc1_device_t *device, uint32_t *out_size,
gralloc1_buffer_descriptor_t descriptor) { char *out_buffer) {
if (!device || !BUF_DESCRIPTOR(descriptor)->IsValid()) { if (!device) {
ALOGE("Gralloc Error : device=%p, descriptor=%p", (void *)device, (void *)descriptor); ALOGE("Gralloc Error : device=%p", (void *)device);
return GRALLOC1_ERROR_BAD_DESCRIPTOR; return GRALLOC1_ERROR_BAD_DESCRIPTOR;
} }
if (out_buffer == nullptr) {
*out_size = 1024;
} else {
std::ostringstream os;
// TODO(user): implement in buffer manager
os << "-------------------------------" << std::endl;
os << "QTI gralloc dump:" << std::endl;
os << "-------------------------------" << std::endl;
auto copy_size = os.str().size() < *out_size ? os.str().size() : *out_size;
std::copy_n(out_buffer, copy_size, os.str().begin());
*out_size = static_cast<uint32_t>(copy_size);
}
return GRALLOC1_ERROR_NONE; return GRALLOC1_ERROR_NONE;
} }
@@ -206,69 +207,66 @@ gralloc1_error_t GrallocImpl::CreateBufferDescriptor(gralloc1_device_t *device,
if (!device) { if (!device) {
return GRALLOC1_ERROR_BAD_DESCRIPTOR; return GRALLOC1_ERROR_BAD_DESCRIPTOR;
} }
GrallocImpl const *dev = GRALLOC_IMPL(device);
BufferDescriptor *descriptor = new BufferDescriptor(); return dev->buf_mgr_->CreateBufferDescriptor(out_descriptor);
if (descriptor == NULL) {
return GRALLOC1_ERROR_NO_RESOURCES;
}
*out_descriptor = reinterpret_cast<gralloc1_buffer_descriptor_t>(descriptor);
return GRALLOC1_ERROR_NONE;
} }
gralloc1_error_t GrallocImpl::DestroyBufferDescriptor(gralloc1_device_t *device, gralloc1_error_t GrallocImpl::DestroyBufferDescriptor(gralloc1_device_t *device,
gralloc1_buffer_descriptor_t descriptor) { gralloc1_buffer_descriptor_t descriptor) {
gralloc1_error_t status = CheckDeviceAndDescriptor(device, descriptor); if (!device) {
if (status == GRALLOC1_ERROR_NONE) { return GRALLOC1_ERROR_BAD_DESCRIPTOR;
delete reinterpret_cast<BufferDescriptor *>(descriptor);
} }
GrallocImpl const *dev = GRALLOC_IMPL(device);
return status; return dev->buf_mgr_->DestroyBufferDescriptor(descriptor);
} }
gralloc1_error_t GrallocImpl::SetConsumerUsage(gralloc1_device_t *device, gralloc1_error_t GrallocImpl::SetConsumerUsage(gralloc1_device_t *device,
gralloc1_buffer_descriptor_t descriptor, gralloc1_buffer_descriptor_t descriptor,
gralloc1_consumer_usage_t usage) { gralloc1_consumer_usage_t usage) {
gralloc1_error_t status = CheckDeviceAndDescriptor(device, descriptor); if (!device) {
if (status == GRALLOC1_ERROR_NONE) { return GRALLOC1_ERROR_BAD_DESCRIPTOR;
BUF_DESCRIPTOR(descriptor)->SetConsumerUsage(usage); } else {
GrallocImpl const *dev = GRALLOC_IMPL(device);
return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
&BufferDescriptor::SetConsumerUsage, usage);
} }
return status;
} }
gralloc1_error_t GrallocImpl::SetBufferDimensions(gralloc1_device_t *device, gralloc1_error_t GrallocImpl::SetBufferDimensions(gralloc1_device_t *device,
gralloc1_buffer_descriptor_t descriptor, gralloc1_buffer_descriptor_t descriptor,
uint32_t width, uint32_t height) { uint32_t width, uint32_t height) {
gralloc1_error_t status = CheckDeviceAndDescriptor(device, descriptor); if (!device) {
if (status == GRALLOC1_ERROR_NONE) { return GRALLOC1_ERROR_BAD_DESCRIPTOR;
BUF_DESCRIPTOR(descriptor)->SetDimensions(INT(width), INT(height)); } else {
GrallocImpl const *dev = GRALLOC_IMPL(device);
return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
&BufferDescriptor::SetDimensions,
INT(width), INT(height));
} }
return status;
} }
gralloc1_error_t GrallocImpl::SetColorFormat(gralloc1_device_t *device, gralloc1_error_t GrallocImpl::SetColorFormat(gralloc1_device_t *device,
gralloc1_buffer_descriptor_t descriptor, gralloc1_buffer_descriptor_t descriptor,
int32_t format) { int32_t format) {
gralloc1_error_t status = CheckDeviceAndDescriptor(device, descriptor); if (!device) {
if (status == GRALLOC1_ERROR_NONE) { return GRALLOC1_ERROR_BAD_DESCRIPTOR;
BUF_DESCRIPTOR(descriptor)->SetColorFormat(format); } else {
GrallocImpl const *dev = GRALLOC_IMPL(device);
return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
&BufferDescriptor::SetColorFormat, format);
} }
return status;
} }
gralloc1_error_t GrallocImpl::SetProducerUsage(gralloc1_device_t *device, gralloc1_error_t GrallocImpl::SetProducerUsage(gralloc1_device_t *device,
gralloc1_buffer_descriptor_t descriptor, gralloc1_buffer_descriptor_t descriptor,
gralloc1_producer_usage_t usage) { gralloc1_producer_usage_t usage) {
gralloc1_error_t status = CheckDeviceAndDescriptor(device, descriptor); if (!device) {
if (status == GRALLOC1_ERROR_NONE) { return GRALLOC1_ERROR_BAD_DESCRIPTOR;
BUF_DESCRIPTOR(descriptor)->SetProducerUsage(usage); } else {
GrallocImpl const *dev = GRALLOC_IMPL(device);
return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
&BufferDescriptor::SetProducerUsage, usage);
} }
return status;
} }
gralloc1_error_t GrallocImpl::GetBackingStore(gralloc1_device_t *device, buffer_handle_t buffer, gralloc1_error_t GrallocImpl::GetBackingStore(gralloc1_device_t *device, buffer_handle_t buffer,
@@ -336,16 +334,16 @@ gralloc1_error_t GrallocImpl::GetBufferStride(gralloc1_device_t *device, buffer_
return status; return status;
} }
gralloc1_error_t GrallocImpl::AllocateBuffers(gralloc1_device_t *device, uint32_t num_dptors, gralloc1_error_t GrallocImpl::AllocateBuffers(gralloc1_device_t *device, uint32_t num_descriptors,
const gralloc1_buffer_descriptor_t *dptors, const gralloc1_buffer_descriptor_t *descriptors,
buffer_handle_t *outBuffers) { buffer_handle_t *out_buffers) {
if (!num_dptors || !dptors) { if (!num_descriptors || !descriptors) {
return GRALLOC1_ERROR_BAD_DESCRIPTOR; return GRALLOC1_ERROR_BAD_DESCRIPTOR;
} }
GrallocImpl const *dev = GRALLOC_IMPL(device); GrallocImpl const *dev = GRALLOC_IMPL(device);
const BufferDescriptor *descriptors = reinterpret_cast<const BufferDescriptor *>(dptors); gralloc1_error_t status = dev->buf_mgr_->AllocateBuffers(num_descriptors, descriptors,
gralloc1_error_t status = dev->buf_mgr_->AllocateBuffers(num_dptors, descriptors, outBuffers); out_buffers);
return status; return status;
} }
@@ -372,6 +370,17 @@ gralloc1_error_t GrallocImpl::ReleaseBuffer(gralloc1_device_t *device, buffer_ha
return status; return status;
} }
gralloc1_error_t GrallocImpl::GetNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer,
uint32_t *out_num_planes) {
gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
if (status == GRALLOC1_ERROR_NONE) {
GrallocImpl const *dev = GRALLOC_IMPL(device);
const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
status = dev->buf_mgr_->GetNumFlexPlanes(hnd, out_num_planes);
}
return status;
}
gralloc1_error_t GrallocImpl::LockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, gralloc1_error_t GrallocImpl::LockBuffer(gralloc1_device_t *device, buffer_handle_t buffer,
gralloc1_producer_usage_t prod_usage, gralloc1_producer_usage_t prod_usage,
gralloc1_consumer_usage_t cons_usage, gralloc1_consumer_usage_t cons_usage,
@@ -392,14 +401,16 @@ gralloc1_error_t GrallocImpl::LockBuffer(gralloc1_device_t *device, buffer_handl
// Either producer usage or consumer usage must be *_USAGE_NONE // Either producer usage or consumer usage must be *_USAGE_NONE
if ((prod_usage != GRALLOC1_PRODUCER_USAGE_NONE) && if ((prod_usage != GRALLOC1_PRODUCER_USAGE_NONE) &&
(cons_usage != GRALLOC1_CONSUMER_USAGE_NONE)) { (cons_usage != GRALLOC1_CONSUMER_USAGE_NONE)) {
return GRALLOC1_ERROR_BAD_VALUE; // Current gralloc1 clients do not satisfy this restriction.
// See b/33588773 for details
// return GRALLOC1_ERROR_BAD_VALUE;
} }
// currently we ignore the region/rect client wants to lock // currently we ignore the region/rect client wants to lock
if (region == NULL) { if (region == NULL) {
return GRALLOC1_ERROR_BAD_VALUE; return GRALLOC1_ERROR_BAD_VALUE;
} }
// TODO(user): Need to check if buffer was allocated with the same flags
status = dev->buf_mgr_->LockBuffer(hnd, prod_usage, cons_usage); status = dev->buf_mgr_->LockBuffer(hnd, prod_usage, cons_usage);
*out_data = reinterpret_cast<void *>(hnd->base); *out_data = reinterpret_cast<void *>(hnd->base);
@@ -407,27 +418,24 @@ gralloc1_error_t GrallocImpl::LockBuffer(gralloc1_device_t *device, buffer_handl
return status; return status;
} }
/* TODO(user) : LOCK_YCBCR changed to LOCK_FLEX but structure definition is not known yet. gralloc1_error_t GrallocImpl::LockFlex(gralloc1_device_t *device, buffer_handle_t buffer,
* Need to implement after clarification from Google. gralloc1_producer_usage_t prod_usage,
gralloc1_error_t GrallocImpl::LockYCbCrBuffer(gralloc1_device_t* device, buffer_handle_t buffer, gralloc1_consumer_usage_t cons_usage,
gralloc1_producer_usage_t prod_usage, gralloc1_consumer_usage_t cons_usage, const gralloc1_rect_t *region,
const gralloc1_rect_t* region, struct android_ycbcr* outYCbCr, int32_t* outAcquireFence) { struct android_flex_layout *out_flex_layout,
gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); int32_t acquire_fence) {
void *out_data;
if (status == GRALLOC1_ERROR_NONE) { gralloc1_error_t status = GrallocImpl::LockBuffer(device, buffer, prod_usage, cons_usage, region,
void **outData = 0; &out_data, acquire_fence);
status = LockBuffer(device, buffer, prod_usage, cons_usage, region, outData, outAcquireFence); if (status != GRALLOC1_ERROR_NONE) {
return status;
} }
if (status == GRALLOC1_ERROR_NONE) {
const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
GrallocImpl const *dev = GRALLOC_IMPL(device); GrallocImpl const *dev = GRALLOC_IMPL(device);
dev->allocator_->GetYUVPlaneInfo(hnd, outYCbCr); const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
} dev->buf_mgr_->GetFlexLayout(hnd, out_flex_layout);
return status; return status;
} }
*/
gralloc1_error_t GrallocImpl::UnlockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, gralloc1_error_t GrallocImpl::UnlockBuffer(gralloc1_device_t *device, buffer_handle_t buffer,
int32_t *release_fence) { int32_t *release_fence) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, The Linux Foundation. All rights reserved. * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
@@ -44,7 +44,6 @@ namespace gralloc1 {
class GrallocImpl : public gralloc1_device_t { class GrallocImpl : public gralloc1_device_t {
public: public:
explicit GrallocImpl(const private_module_t *module);
~GrallocImpl(); ~GrallocImpl();
bool Init(); bool Init();
static int CloseDevice(hw_device_t *device); static int CloseDevice(hw_device_t *device);
@@ -53,9 +52,14 @@ class GrallocImpl : public gralloc1_device_t {
static gralloc1_function_pointer_t GetFunction( static gralloc1_function_pointer_t GetFunction(
struct gralloc1_device *device, int32_t /*gralloc1_function_descriptor_t*/ descriptor); struct gralloc1_device *device, int32_t /*gralloc1_function_descriptor_t*/ descriptor);
static GrallocImpl* GetInstance(const struct hw_module_t *module) {
static GrallocImpl *instance = new GrallocImpl(module);
return instance;
}
private: private:
static inline gralloc1_error_t CheckDeviceAndDescriptor(gralloc1_device_t *device, static inline gralloc1_error_t Dump(gralloc1_device_t *device, uint32_t *out_size,
gralloc1_buffer_descriptor_t descriptor); char *out_buffer);
static inline gralloc1_error_t CheckDeviceAndHandle(gralloc1_device_t *device, static inline gralloc1_error_t CheckDeviceAndHandle(gralloc1_device_t *device,
buffer_handle_t buffer); buffer_handle_t buffer);
static gralloc1_error_t CreateBufferDescriptor(gralloc1_device_t *device, static gralloc1_error_t CreateBufferDescriptor(gralloc1_device_t *device,
@@ -90,29 +94,25 @@ class GrallocImpl : public gralloc1_device_t {
buffer_handle_t *out_buffers); buffer_handle_t *out_buffers);
static gralloc1_error_t RetainBuffer(gralloc1_device_t *device, buffer_handle_t buffer); static gralloc1_error_t RetainBuffer(gralloc1_device_t *device, buffer_handle_t buffer);
static gralloc1_error_t ReleaseBuffer(gralloc1_device_t *device, buffer_handle_t buffer); static gralloc1_error_t ReleaseBuffer(gralloc1_device_t *device, buffer_handle_t buffer);
static gralloc1_error_t getNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer, static gralloc1_error_t GetNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer,
uint32_t *out_num_planes); uint32_t *out_num_planes);
static gralloc1_error_t LockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, static gralloc1_error_t LockBuffer(gralloc1_device_t *device, buffer_handle_t buffer,
gralloc1_producer_usage_t prod_usage, gralloc1_producer_usage_t prod_usage,
gralloc1_consumer_usage_t cons_usage, gralloc1_consumer_usage_t cons_usage,
const gralloc1_rect_t *access_region, void **out_data, const gralloc1_rect_t *region, void **out_data,
int32_t acquire_fence); int32_t acquire_fence);
static gralloc1_error_t LockFlex(gralloc1_device_t *device, buffer_handle_t buffer, static gralloc1_error_t LockFlex(gralloc1_device_t *device, buffer_handle_t buffer,
gralloc1_producer_usage_t prod_usage, gralloc1_producer_usage_t prod_usage,
gralloc1_consumer_usage_t cons_usage, gralloc1_consumer_usage_t cons_usage,
const gralloc1_rect_t *access_region, const gralloc1_rect_t *region,
struct android_flex_layout *out_flex_layout, struct android_flex_layout *out_flex_layout,
int32_t acquireFence); int32_t acquire_fence);
/* TODO(user) : LOCK_YCBCR changed to LOCK_FLEX but structure is not known yet.
* Need to implement after clarification from Google.
static gralloc1_error_t LockYCbCrBuffer(gralloc1_device_t* device, buffer_handle_t buffer,
gralloc1_producer_usage_t producerUsage, gralloc1_consumer_usage_t consumerUsage,
const gralloc1_rect_t* Region, struct android_ycbcr* outYCbCr, int32_t* outAcquireFence);
*/
static gralloc1_error_t UnlockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, static gralloc1_error_t UnlockBuffer(gralloc1_device_t *device, buffer_handle_t buffer,
int32_t *release_fence); int32_t *release_fence);
static gralloc1_error_t Gralloc1Perform(gralloc1_device_t *device, int operation, ...); static gralloc1_error_t Gralloc1Perform(gralloc1_device_t *device, int operation, ...);
explicit GrallocImpl(const hw_module_t *module);
BufferManager *buf_mgr_ = NULL; BufferManager *buf_mgr_ = NULL;
}; };

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. * Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
@@ -106,21 +106,26 @@ int IonAlloc::AllocBuffer(AllocData *data) {
data->base = base; data->base = base;
data->fd = fd_data.fd; data->fd = fd_data.fd;
ioctl(ion_dev_fd_, INT(ION_IOC_FREE), &handle_data); data->ion_handle = handle_data.handle;
ALOGD_IF(DEBUG, "ion: Allocated buffer base:%p size:%zu fd:%d", data->base, ion_alloc_data.len, ALOGD_IF(DEBUG, "ion: Allocated buffer base:%p size:%zu fd:%d handle:0x%x", data->base,
data->fd); ion_alloc_data.len, data->fd, data->ion_handle);
return 0; return 0;
} }
int IonAlloc::FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd) { int IonAlloc::FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd,
int ion_handle) {
ATRACE_CALL(); ATRACE_CALL();
int err = 0; int err = 0;
ALOGD_IF(DEBUG, "ion: Freeing buffer base:%p size:%u fd:%d", base, size, fd); ALOGD_IF(DEBUG, "ion: Freeing buffer base:%p size:%u fd:%d handle:0x%x", base, size, fd,
ion_handle);
if (base) { if (base) {
err = UnmapBuffer(base, size, offset); err = UnmapBuffer(base, size, offset);
} }
struct ion_handle_data handle_data;
handle_data.handle = ion_handle;
ioctl(ion_dev_fd_, INT(ION_IOC_FREE), &handle_data);
close(fd); close(fd);
return err; return err;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. * Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
@@ -45,6 +45,7 @@ enum {
struct AllocData { struct AllocData {
void *base = NULL; void *base = NULL;
int fd = -1; int fd = -1;
int ion_handle = -1;
unsigned int offset = 0; unsigned int offset = 0;
unsigned int size = 0; unsigned int size = 0;
unsigned int align = 1; unsigned int align = 1;
@@ -63,7 +64,7 @@ class IonAlloc {
bool Init(); bool Init();
int AllocBuffer(AllocData *data); int AllocBuffer(AllocData *data);
int FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd); int FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, int ion_handle);
int MapBuffer(void **base, unsigned int size, unsigned int offset, int fd); int MapBuffer(void **base, unsigned int size, unsigned int offset, int fd);
int UnmapBuffer(void *base, unsigned int size, unsigned int offset); int UnmapBuffer(void *base, unsigned int size, unsigned int offset);
int CleanBuffer(void *base, unsigned int size, unsigned int offset, int fd, int op); int CleanBuffer(void *base, unsigned int size, unsigned int offset, int fd, int op);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011-2016, The Linux Foundation. All rights reserved. * Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
* Not a Contribution * Not a Contribution
* *
* Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
@@ -22,6 +22,7 @@
#include <cutils/log.h> #include <cutils/log.h>
#include <hardware/gralloc1.h> #include <hardware/gralloc1.h>
#include <hardware/gralloc.h>
#define GRALLOC1_FUNCTION_PERFORM 0x00001000 #define GRALLOC1_FUNCTION_PERFORM 0x00001000
@@ -29,20 +30,15 @@
typedef gralloc1_error_t (*GRALLOC1_PFN_PERFORM)(gralloc1_device_t *device, int operation, ...); typedef gralloc1_error_t (*GRALLOC1_PFN_PERFORM)(gralloc1_device_t *device, int operation, ...);
typedef int BackStoreFd;
#define PRIV_HANDLE_CONST(exp) static_cast<const private_handle_t *>(exp) #define PRIV_HANDLE_CONST(exp) static_cast<const private_handle_t *>(exp)
struct private_handle_t : public native_handle_t { struct private_handle_t : public native_handle_t {
// TODO(user): Moving PRIV_FLAGS to #defs & check for each PRIV_FLAG and remove unused.
enum { enum {
PRIV_FLAGS_FRAMEBUFFER = 0x00000001, PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
PRIV_FLAGS_USES_ION = 0x00000008, PRIV_FLAGS_USES_ION = 0x00000008,
PRIV_FLAGS_USES_ASHMEM = 0x00000010,
PRIV_FLAGS_NEEDS_FLUSH = 0x00000020, PRIV_FLAGS_NEEDS_FLUSH = 0x00000020,
PRIV_FLAGS_INTERNAL_ONLY = 0x00000040, PRIV_FLAGS_INTERNAL_ONLY = 0x00000040,
PRIV_FLAGS_NON_CPU_WRITER = 0x00000080, PRIV_FLAGS_NON_CPU_WRITER = 0x00000080,
PRIV_FLAGS_NONCONTIGUOUS_MEM = 0x00000100,
PRIV_FLAGS_CACHED = 0x00000200, PRIV_FLAGS_CACHED = 0x00000200,
PRIV_FLAGS_SECURE_BUFFER = 0x00000400, PRIV_FLAGS_SECURE_BUFFER = 0x00000400,
PRIV_FLAGS_EXTERNAL_ONLY = 0x00002000, PRIV_FLAGS_EXTERNAL_ONLY = 0x00002000,
@@ -59,36 +55,31 @@ struct private_handle_t : public native_handle_t {
PRIV_FLAGS_TILE_RENDERED = 0x02000000, PRIV_FLAGS_TILE_RENDERED = 0x02000000,
PRIV_FLAGS_CPU_RENDERED = 0x04000000, PRIV_FLAGS_CPU_RENDERED = 0x04000000,
PRIV_FLAGS_UBWC_ALIGNED = 0x08000000, PRIV_FLAGS_UBWC_ALIGNED = 0x08000000,
PRIV_FLAGS_DISP_CONSUMER = 0x10000000 PRIV_FLAGS_DISP_CONSUMER = 0x10000000,
PRIV_FLAGS_CLIENT_ALLOCATED = 0x20000000, // Ion buffer allocated outside of gralloc
}; };
// file-descriptors // file-descriptors dup'd over IPC
int fd; int fd;
int fd_metadata; int fd_metadata;
// ints // values sent over IPC
int magic; int magic;
int flags; int flags;
unsigned int size;
unsigned int offset;
int buffer_type;
uint64_t base __attribute__((aligned(8)));
unsigned int offset_metadata;
// The gpu address mapped into the mmu.
uint64_t gpuaddr __attribute__((aligned(8)));
int format;
int width; // holds width of the actual buffer allocated int width; // holds width of the actual buffer allocated
int height; // holds height of the actual buffer allocated int height; // holds height of the actual buffer allocated
int stride;
uint64_t base_metadata __attribute__((aligned(8)));
unsigned int fb_id;
// added for gralloc1
int unaligned_width; // holds width client asked to allocate int unaligned_width; // holds width client asked to allocate
int unaligned_height; // holds height client asked to allocate int unaligned_height; // holds height client asked to allocate
int format;
int buffer_type;
unsigned int size;
unsigned int offset;
unsigned int offset_metadata;
unsigned int fb_id;
uint64_t base __attribute__((aligned(8)));
uint64_t base_metadata __attribute__((aligned(8)));
uint64_t gpuaddr __attribute__((aligned(8)));
uint64_t id __attribute__((aligned(8)));
gralloc1_producer_usage_t producer_usage __attribute__((aligned(8))); gralloc1_producer_usage_t producer_usage __attribute__((aligned(8)));
gralloc1_consumer_usage_t consumer_usage __attribute__((aligned(8))); gralloc1_consumer_usage_t consumer_usage __attribute__((aligned(8)));
@@ -96,58 +87,57 @@ struct private_handle_t : public native_handle_t {
static const int kMagic = 'gmsm'; static const int kMagic = 'gmsm';
static inline int NumInts() { static inline int NumInts() {
return ((sizeof(private_handle_t) - sizeof(native_handle_t)) / sizeof(int)) - kNumFds; return ((sizeof(private_handle_t) - sizeof(native_handle_t)) / sizeof(int))
- kNumFds;
} }
private_handle_t(int fd, unsigned int size, int flags, int buf_type, int format, int width, private_handle_t(int fd,
int height) int meta_fd,
int flags,
int width,
int height,
int uw,
int uh,
int format,
int buf_type,
unsigned int size,
gralloc1_producer_usage_t prod_usage = GRALLOC1_PRODUCER_USAGE_NONE,
gralloc1_consumer_usage_t cons_usage = GRALLOC1_CONSUMER_USAGE_NONE)
: fd(fd), : fd(fd),
fd_metadata(-1), fd_metadata(meta_fd),
magic(kMagic), magic(kMagic),
flags(flags), flags(flags),
size(size),
offset(0),
buffer_type(buf_type),
base(0),
offset_metadata(0),
gpuaddr(0),
format(format),
width(width), width(width),
height(height), height(height),
unaligned_width(uw),
unaligned_height(uh),
format(format),
buffer_type(buf_type),
size(size),
offset(0),
offset_metadata(0),
fb_id(0),
base(0),
base_metadata(0), base_metadata(0),
unaligned_width(width), gpuaddr(0),
unaligned_height(height), id(0),
producer_usage(GRALLOC1_PRODUCER_USAGE_NONE), producer_usage(prod_usage),
consumer_usage(GRALLOC1_CONSUMER_USAGE_NONE), consumer_usage(cons_usage) {
fb_id(0) {
version = static_cast<int>(sizeof(native_handle)); version = static_cast<int>(sizeof(native_handle));
numInts = NumInts(); numInts = NumInts();
numFds = kNumFds; numFds = kNumFds;
} }
private_handle_t(int fd, unsigned int size, int flags, int buf_type, int format, int width, // Legacy constructor used by some clients
int height, int meta_fd, unsigned int meta_offset, uint64_t meta_base) private_handle_t(int fd, unsigned int size, int usage, int buf_type, int format, int w, int h)
: private_handle_t(fd, size, flags, buf_type, format, width, height) { : private_handle_t(fd, -1, PRIV_FLAGS_CLIENT_ALLOCATED, w, h, 0, 0, format, buf_type, size,
fd_metadata = meta_fd; static_cast<gralloc1_producer_usage_t>(usage),
offset_metadata = meta_offset; static_cast<gralloc1_consumer_usage_t>(usage)) {
base_metadata = meta_base;
}
private_handle_t(int fd, unsigned int size, int flags, int buf_type, int format, int width,
int height, int meta_fd, unsigned int meta_offset, uint64_t meta_base,
int unaligned_w , int unaligned_h,
gralloc1_producer_usage_t prod_usage, gralloc1_consumer_usage_t cons_usage)
: private_handle_t(fd, size, flags, buf_type, format, width, height, meta_fd, meta_offset
meta_base) {
unaligned_width = unaligned_w;
unaligned_height = unaligned_h;
producer_usage = prod_usage;
consumer_usage = cons_usage;
} }
~private_handle_t() { ~private_handle_t() {
magic = 0; magic = 0;
ALOGE_IF(DBG_HANDLE, "deleting buffer handle %p", this); ALOGE_IF(DBG_HANDLE, "Deleting buffer handle %p", this);
} }
static int validate(const native_handle *h) { static int validate(const native_handle *h) {
@@ -177,8 +167,7 @@ struct private_handle_t : public native_handle_t {
int GetColorFormat() const { return format; } int GetColorFormat() const { return format; }
int GetStride() const { int GetStride() const {
// In handle we are storing aligned width after allocation. // In handle we currently store aligned width after allocation.
// Why GetWidth & GetStride?? Are we supposed to maintain unaligned values??
return width; return width;
} }
@@ -186,7 +175,7 @@ struct private_handle_t : public native_handle_t {
gralloc1_producer_usage_t GetProducerUsage() const { return producer_usage; } gralloc1_producer_usage_t GetProducerUsage() const { return producer_usage; }
BackStoreFd GetBackingstore() const { return fd; } int GetBackingstore() const { return fd; }
}; };
#endif // __GR_PRIV_HANDLE_H__ #endif // __GR_PRIV_HANDLE_H__

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011-2016, The Linux Foundation. All rights reserved. * Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
* Not a Contribution * Not a Contribution
* *
* Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
@@ -24,50 +24,64 @@
#include "gr_priv_handle.h" #include "gr_priv_handle.h"
#define ROUND_UP_PAGESIZE(x) roundUpToPageSize(x) #define ROUND_UP_PAGESIZE(x) roundUpToPageSize(x)
inline unsigned int roundUpToPageSize(unsigned int x) { inline int roundUpToPageSize(int x) {
return (x + (getpagesize()-1)) & ~(getpagesize()-1); return (x + (getpagesize()-1)) & ~(getpagesize()-1);
} }
/* Gralloc usage bits indicating the type of allocation that should be used */ /* Gralloc usage bits indicating the type of allocation that should be used */
/* Refer gralloc1_producer_usage_t & gralloc1_consumer_usage-t in gralloc1.h */ /* Refer gralloc1_producer_usage_t & gralloc1_consumer_usage-t in gralloc1.h */
/* GRALLOC_USAGE_PRIVATE_0 is unused */ /* Producer flags */
/* Non linear, Universal Bandwidth Compression */ /* Non linear, Universal Bandwidth Compression */
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_ALLOC_UBWC GRALLOC1_PRODUCER_USAGE_PRIVATE_1 #define GRALLOC1_PRODUCER_USAGE_PRIVATE_ALLOC_UBWC GRALLOC1_PRODUCER_USAGE_PRIVATE_0
/* IOMMU heap comes from manually allocated pages, can be cached/uncached, is not secured */
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_IOMMU_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_2
/* MM heap is a carveout heap for video, can be secured */
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_MM_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_3
/* ADSP heap is a carveout heap, is not secured */
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_ADSP_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_4
/* CAMERA heap is a carveout heap for camera, is not secured */
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_CAMERA_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_5
/* Set this for allocating uncached memory (using O_DSYNC), /* Set this for allocating uncached memory (using O_DSYNC),
* cannot be used with noncontiguous heaps */ * cannot be used with noncontiguous heaps */
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_UNCACHED GRALLOC1_PRODUCER_USAGE_PRIVATE_6 #define GRALLOC1_PRODUCER_USAGE_PRIVATE_UNCACHED GRALLOC1_PRODUCER_USAGE_PRIVATE_1
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_CAMERA_ZSL GRALLOC1_PRODUCER_USAGE_PRIVATE_7 /* CAMERA heap is a carveout heap for camera, is not secured */
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_CAMERA_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_2
/* Buffer content should be displayed on a primary display only */ /* ADSP heap is a carveout heap, is not secured */
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_INTERNAL_ONLY GRALLOC1_CONSUMER_USAGE_PRIVATE_1 #define GRALLOC1_PRODUCER_USAGE_PRIVATE_ADSP_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_3
/* Buffer content should be displayed on an external display only */ /* IOMMU heap comes from manually allocated pages, can be cached/uncached, is not secured */
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_EXTERNAL_ONLY GRALLOC1_CONSUMER_USAGE_PRIVATE_2 #define GRALLOC1_PRODUCER_USAGE_PRIVATE_IOMMU_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_4
/* MM heap is a carveout heap for video, can be secured */
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_MM_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_5
/* Use legacy ZSL definition until we know the correct usage on gralloc1 */
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_CAMERA_ZSL GRALLOC_USAGE_HW_CAMERA_ZSL
/* Consumer flags */
/* TODO(user): Fix when producer and consumer flags are actually separated */
/* This flag is set for WFD usecase */ /* This flag is set for WFD usecase */
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_WFD GRALLOC1_CONSUMER_USAGE_PRIVATE_3 #define GRALLOC1_CONSUMER_USAGE_PRIVATE_WFD 0x00200000
/* This flag is used for SECURE display usecase */ /* This flag is used for SECURE display usecase */
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY GRALLOC1_CONSUMER_USAGE_PRIVATE_4 #define GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY 0x00800000
/* Buffer content should be displayed on a primary display only */
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_INTERNAL_ONLY 0x04000000
/* Buffer content should be displayed on an external display only */
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_EXTERNAL_ONLY 0x08000000
/* Legacy gralloc0.x definitions */
/* Some clients may still be using the old flags */
#define GRALLOC_USAGE_PRIVATE_ALLOC_UBWC GRALLOC1_PRODUCER_USAGE_PRIVATE_ALLOC_UBWC
#define GRALLOC_USAGE_PRIVATE_UNCACHED GRALLOC1_PRODUCER_USAGE_PRIVATE_UNCACHED
#define GRALLOC_USAGE_PRIVATE_IOMMU_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_IOMMU_HEAP
#define GRALLOC_USAGE_PRIVATE_WFD GRALLOC1_CONSUMER_USAGE_PRIVATE_WFD
#define GRALLOC_USAGE_PRIVATE_CAMERA_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_CAMERA_HEAP
#define GRALLOC_USAGE_PRIVATE_MM_HEAP 0x0
// for PERFORM API : // for PERFORM API :
// TODO(user): Move it to enum if it's ookay for gfx
#define GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER 1 #define GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER 1
#define GRALLOC_MODULE_PERFORM_GET_STRIDE 2 #define GRALLOC_MODULE_PERFORM_GET_STRIDE 2
#define GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE 3 #define GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE 3
@@ -81,6 +95,8 @@ inline unsigned int roundUpToPageSize(unsigned int x) {
#define GRALLOC_MODULE_PERFORM_GET_IGC 11 #define GRALLOC_MODULE_PERFORM_GET_IGC 11
#define GRALLOC_MODULE_PERFORM_SET_IGC 12 #define GRALLOC_MODULE_PERFORM_SET_IGC 12
#define GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE 13 #define GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE 13
#define GRALLOC1_MODULE_PERFORM_GET_BUFFER_SIZE_AND_DIMENSIONS 14
#define GRALLOC1_MODULE_PERFORM_ALLOCATE_BUFFER 15
// OEM specific HAL formats // OEM specific HAL formats
#define HAL_PIXEL_FORMAT_RGBA_5551 6 #define HAL_PIXEL_FORMAT_RGBA_5551 6

View File

@@ -16,9 +16,13 @@ LOCAL_CFLAGS := -Wno-missing-field-initializers -Wno-unused-par
LOCAL_CLANG := true LOCAL_CLANG := true
LOCAL_SHARED_LIBRARIES := libsdmcore libqservice libbinder libhardware libhardware_legacy \ LOCAL_SHARED_LIBRARIES := libsdmcore libqservice libbinder libhardware libhardware_legacy \
libutils libcutils libsync libmemalloc libqdutils libdl \ libutils libcutils libsync libqdutils libdl \
libpowermanager libsdmutils libc++ liblog libpowermanager libsdmutils libc++ liblog
ifneq ($(TARGET_USES_GRALLOC1), true)
LOCAL_SHARED_LIBRARIES += libmemalloc
endif
LOCAL_SRC_FILES := hwc_session.cpp \ LOCAL_SRC_FILES := hwc_session.cpp \
hwc_display.cpp \ hwc_display.cpp \
hwc_display_primary.cpp \ hwc_display_primary.cpp \