diff --git a/cros_gralloc/cros_gralloc_helpers.cc b/cros_gralloc/cros_gralloc_helpers.cc index 8749720e..464ce8c3 100644 --- a/cros_gralloc/cros_gralloc_helpers.cc +++ b/cros_gralloc/cros_gralloc_helpers.cc @@ -117,7 +117,7 @@ int32_t cros_gralloc_sync_wait(int32_t fence, bool close_fence) */ int err = sync_wait(fence, 1000); if (err < 0) { - drv_log("Timed out on sync wait, err = %s\n", strerror(errno)); + drv_info("Timed out on sync wait, err = %s\n", strerror(errno)); err = sync_wait(fence, -1); if (err < 0) { drv_log("sync wait error = %s\n", strerror(errno)); @@ -148,7 +148,7 @@ int32_t cros_gralloc_sync_wait(int32_t acquire_fence) */ int err = sync_wait(acquire_fence, 1000); if (err < 0) { - drv_log("Timed out on sync wait, err = %s", strerror(errno)); + drv_info("Timed out on sync wait, err = %s", strerror(errno)); err = sync_wait(acquire_fence, -1); if (err < 0) { drv_log("sync wait error = %s", strerror(errno)); diff --git a/cros_gralloc/gralloc1/cros_gralloc1_module.cc b/cros_gralloc/gralloc1/cros_gralloc1_module.cc index e062f729..841b15ea 100644 --- a/cros_gralloc/gralloc1/cros_gralloc1_module.cc +++ b/cros_gralloc/gralloc1/cros_gralloc1_module.cc @@ -243,7 +243,7 @@ gralloc1_function_pointer_t CrosGralloc1::doGetFunction(int32_t intDescriptor) void CrosGralloc1::dump(uint32_t *outSize, char *outBuffer) { - drv_log("dump(%u (%p), %p", outSize ? *outSize : 0, outSize, outBuffer); + drv_info("dump(%u (%p), %p", outSize ? *outSize : 0, outSize, outBuffer); } int32_t CrosGralloc1::createDescriptor(gralloc1_buffer_descriptor_t *outDescriptor) @@ -466,18 +466,21 @@ int32_t CrosGralloc1::lock(buffer_handle_t bufferHandle, gralloc1_producer_usage map_flags = cros_gralloc1_convert_map_usage(producerUsage, consumerUsage); if (driver->lock(bufferHandle, acquireFence, map_flags, addr)) { - drv_log("Plz switch to mapper 4.0 or call importBuffer & freeBuffer with mapper 2.0 before lock"); - buffer_handle_t buffer_handle = native_handle_clone(bufferHandle); - auto error = retain(buffer_handle); - if (error != GRALLOC1_ERROR_NONE) { - delete buffer_handle; - return error; - } - bufferHandle = buffer_handle; - if (driver->lock(bufferHandle, acquireFence, map_flags, addr)) - return CROS_GRALLOC_ERROR_BAD_HANDLE; - delete buffer_handle; - } + drv_info("Plz switch to mapper 4.0 or call importBuffer & freeBuffer with mapper 2.0 before lock"); + buffer_handle_t buffer_handle = native_handle_clone(bufferHandle); + auto error = retain(buffer_handle); + if (error != GRALLOC1_ERROR_NONE) { + drv_log("Retain failed"); + delete buffer_handle; + return error; + } + bufferHandle = buffer_handle; + if (driver->lock(bufferHandle, acquireFence, map_flags, addr)) { + drv_log("lock failed"); + return CROS_GRALLOC_ERROR_BAD_HANDLE; + } + delete buffer_handle; + } *outData = addr[0]; @@ -567,16 +570,19 @@ int32_t CrosGralloc1::lockYCbCr(buffer_handle_t bufferHandle, map_flags = cros_gralloc1_convert_map_usage(producerUsage, consumerUsage); if (driver->lock(bufferHandle, acquireFence, map_flags, addr)) { - drv_log("Plz switch to mapper 4.0 or call importBuffer & freeBuffer with mapper 2.0 before lockFlex"); + drv_info("Plz switch to mapper 4.0 or call importBuffer & freeBuffer with mapper 2.0 before lockFlex"); buffer_handle_t buffer_handle = native_handle_clone(bufferHandle); auto error = retain(buffer_handle); if (error != GRALLOC1_ERROR_NONE) { + drv_log("Retain failed"); delete buffer_handle; return error; } bufferHandle = buffer_handle; - if (driver->lock(bufferHandle, acquireFence, map_flags, addr)) + if (driver->lock(bufferHandle, acquireFence, map_flags, addr)) { + drv_log("lock failed"); return CROS_GRALLOC_ERROR_BAD_HANDLE; + } driver->release(buffer_handle); delete buffer_handle; } diff --git a/cros_gralloc/gralloc4/CrosGralloc4Allocator.cc b/cros_gralloc/gralloc4/CrosGralloc4Allocator.cc index 47f81a6d..4a88e796 100644 --- a/cros_gralloc/gralloc4/CrosGralloc4Allocator.cc +++ b/cros_gralloc/gralloc4/CrosGralloc4Allocator.cc @@ -38,6 +38,7 @@ Error CrosGralloc4Allocator::allocate(const BufferDescriptorInfo& descriptor, ui } if (!outStride || !outHandle) { + drv_log("Invalid params.\n"); return Error::NO_RESOURCES; } @@ -63,6 +64,7 @@ Error CrosGralloc4Allocator::allocate(const BufferDescriptorInfo& descriptor, ui cros_gralloc_handle_t crosHandle = cros_gralloc_convert_handle(handle); if (!crosHandle) { + drv_log("Invalid handle"); return Error::NO_RESOURCES; } diff --git a/cros_gralloc/gralloc4/CrosGralloc4Utils.cc b/cros_gralloc/gralloc4/CrosGralloc4Utils.cc index 38298bcc..8b5b6a53 100644 --- a/cros_gralloc/gralloc4/CrosGralloc4Utils.cc +++ b/cros_gralloc/gralloc4/CrosGralloc4Utils.cc @@ -454,7 +454,6 @@ int convertToCrosDescriptor(const BufferDescriptorInfo& descriptor, if (convertToDrmFormat(descriptor.format, &outCrosDescriptor->drm_format)) { #ifdef USE_GRALLOC1 - drv_log("Failed to convert descriptor by convertToDrmFormat"); if (!IsSupportedYUVFormat(static_cast(descriptor.format))) { std::string pixelFormatString = getPixelFormatString(descriptor.format); drv_log("Failed to convert descriptor. Unsupported fomat %s\n", pixelFormatString.c_str()); diff --git a/cros_gralloc/i915_private_android.cc b/cros_gralloc/i915_private_android.cc index f5d97c42..de47d798 100644 --- a/cros_gralloc/i915_private_android.cc +++ b/cros_gralloc/i915_private_android.cc @@ -78,7 +78,7 @@ int32_t i915_private_invert_format(int format) case DRM_FORMAT_YUV422: return HAL_PIXEL_FORMAT_YCbCr_422_888; default: - drv_log("Unhandled DRM format %4.4s", drmFormat2Str(format)); + drv_info("Unhandled DRM format %4.4s", drmFormat2Str(format)); } return 0; diff --git a/drv.c b/drv.c index c306025c..b99769ad 100644 --- a/drv.c +++ b/drv.c @@ -17,7 +17,6 @@ #include #ifdef __ANDROID__ -#include #include #endif @@ -711,7 +710,7 @@ uint32_t drv_num_buffers_per_bo(struct bo *bo) return count; } -void drv_log_prefix(const char *prefix, const char *file, int line, const char *format, ...) +void drv_log_prefix(const char *prefix, const char *file, int line, android_LogPriority level, const char *format, ...) { char buf[50]; snprintf(buf, sizeof(buf), "[%s:%s(%d)]", prefix, basename(file), line); @@ -719,7 +718,7 @@ void drv_log_prefix(const char *prefix, const char *file, int line, const char * va_list args; va_start(args, format); #ifdef __ANDROID__ - __android_log_vprint(ANDROID_LOG_ERROR, buf, format, args); + __android_log_vprint(level, buf, format, args); #else fprintf(stderr, "%s ", buf); vfprintf(stderr, format, args); diff --git a/drv.h b/drv.h index 04f36199..ef230742 100644 --- a/drv.h +++ b/drv.h @@ -15,6 +15,10 @@ extern "C" { #include #include +#ifdef __ANDROID__ +#include +#endif + #define DRV_MAX_PLANES 4 // clang-format off @@ -192,11 +196,16 @@ uint32_t drv_bo_get_stride_or_tiling(struct bo *bo); #define drv_log(format, ...) \ do { \ - drv_log_prefix("minigbm", __FILE__, __LINE__, format, ##__VA_ARGS__); \ + drv_log_prefix("minigbm", __FILE__, __LINE__, ANDROID_LOG_ERROR, format, ##__VA_ARGS__); \ + } while (0) + +#define drv_info(format, ...) \ + do { \ + drv_log_prefix("minigbm", __FILE__, __LINE__, ANDROID_LOG_INFO, format, ##__VA_ARGS__); \ } while (0) -__attribute__((format(printf, 4, 5))) void drv_log_prefix(const char *prefix, const char *file, - int line, const char *format, ...); +__attribute__((format(printf, 5, 6))) void drv_log_prefix(const char *prefix, const char *file, + int line, android_LogPriority level, const char *format, ...); #ifdef __cplusplus } diff --git a/i915.c b/i915.c index e5b9aea1..ea954899 100644 --- a/i915.c +++ b/i915.c @@ -642,7 +642,7 @@ static int i915_bo_invalidate(struct bo *bo, struct mapping *mapping) ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain); if (ret) { - drv_log("DRM_IOCTL_I915_GEM_SET_DOMAIN with %d\n", ret); + drv_info("DRM_IOCTL_I915_GEM_SET_DOMAIN with %d\n", ret); return ret; } diff --git a/virtio_gpu.c b/virtio_gpu.c index aae24585..f338e0f1 100644 --- a/virtio_gpu.c +++ b/virtio_gpu.c @@ -360,7 +360,7 @@ static void virtio_gpu_add_combination(struct driver *drv, uint32_t drm_format, if (features[feat_3d].enabled && priv->caps.max_version >= 1) { if ((use_flags & BO_USE_SCANOUT) && priv->caps_is_v2 && !virtio_gpu_supports_combination_natively(drv, drm_format, use_flags)) { - drv_log("Scanout format: %d\n", drm_format); + drv_info("Scanout format: %d\n", drm_format); use_flags &= ~BO_USE_SCANOUT; } @@ -430,7 +430,7 @@ static uint32_t use_flags_to_bind(uint64_t use_flags) handle_flag(&use_flags, BO_USE_CAMERA_WRITE, &bind, VIRGL_BIND_LINEAR); if (use_flags) { - drv_log("Unhandled bo use flag: %llx\n", (unsigned long long)use_flags); + drv_info("Unhandled bo use flag: %llx\n", (unsigned long long)use_flags); } return bind;