using aidl::android::hardware::graphics::common::BufferUsage; using aidl::android::hardware::graphics::common::PlaneLayout; using aidl::android::hardware::graphics::common::PlaneLayoutComponent; using aidl::android::hardware::graphics::common::PlaneLayoutComponentType; using android::GraphicBufferMapper; using android::OK; using android::Rect; using android::status_t;
if (width > std::numeric_limits<uint32_t>::max()) {
ALOGE("%s Width too large to cast to uint32_t: %ld", __FUNCTION__, width); return std::nullopt;
} returnstatic_cast<uint32_t>(width);
}
if (height > std::numeric_limits<uint32_t>::max()) {
ALOGE("%s Height too large to cast to uint32_t: %ld", __FUNCTION__, height); return std::nullopt;
} returnstatic_cast<uint32_t>(height);
}
std::optional<uint32_t> Gralloc::GetDrmFormat(buffer_handle_t buffer) {
uint32_t format = 0;
status_t status = GraphicBufferMapper::get().getPixelFormatFourCC(buffer, &format); if (status != OK) { return std::nullopt;
}
return format;
}
std::optional<std::vector<PlaneLayout>> Gralloc::GetPlaneLayouts(buffer_handle_t buffer) {
std::vector<PlaneLayout> layouts;
status_t status = GraphicBufferMapper::get().getPlaneLayouts(buffer, &layouts); if (status != OK) { return std::nullopt;
}
return layouts;
}
std::optional<uint32_t> Gralloc::GetMonoPlanarStrideBytes(buffer_handle_t buffer) { auto plane_layouts_opt = GetPlaneLayouts(buffer); if (!plane_layouts_opt) { return std::nullopt;
}
if (plane_layouts[0].strideInBytes > std::numeric_limits<uint32_t>::max()) {
ALOGE("%s strideInBytes too large to cast to uint32_t: %ld", __FUNCTION__,
plane_layouts[0].strideInBytes); return std::nullopt;
} returnstatic_cast<uint32_t>(plane_layouts[0].strideInBytes);
}
auto width_opt = GetWidth(buffer); if (!width_opt) { return std::nullopt;
}
auto height_opt = GetHeight(buffer); if (!height_opt) { return std::nullopt;
}
Rect buffer_region;
buffer_region.left = 0;
buffer_region.top = 0; // width = right - left
buffer_region.right = static_cast<int32_t>(*width_opt); // height = bottom - top
buffer_region.bottom = static_cast<int32_t>(*height_opt);
void* data = nullptr;
status_t status = GraphicBufferMapper::get().lock(buffer, buffer_usage, buffer_region, &data);
if (status != OK) {
ALOGE("%s failed to lock buffer: %d", __FUNCTION__, status); return std::nullopt;
}
return data;
}
std::optional<android_ycbcr> Gralloc::LockYCbCr(buffer_handle_t buffer) { auto format_opt = GetDrmFormat(buffer); if (!format_opt) {
ALOGE("%s failed to check format of buffer", __FUNCTION__); return std::nullopt;
}
if (*format_opt != DRM_FORMAT_NV12 && *format_opt != DRM_FORMAT_NV21 &&
*format_opt != DRM_FORMAT_YVU420) {
ALOGE("%s called on non-ycbcr buffer", __FUNCTION__); return std::nullopt;
}
auto lock_opt = Lock(buffer); if (!lock_opt) {
ALOGE("%s failed to lock buffer", __FUNCTION__); return std::nullopt;
}
auto plane_layouts_opt = GetPlaneLayouts(buffer); if (!plane_layouts_opt) {
ALOGE("%s failed to get plane layouts", __FUNCTION__); return std::nullopt;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.