static void Image_unlockIfLocked(JNIEnv* env, jobject thiz) { ALOGV("%s", __FUNCTION__); GraphicBuffer* buffer; Image_getNativeContext(env, thiz, &buffer, NULL); if (buffer == NULL) { jniThrowException(env, "java/lang/IllegalStateException", "Image is not initialized"); return; } // Is locked? bool isLocked = false; jobject planes = NULL; if (!isFormatOpaque(buffer->getPixelFormat())) { planes = env->GetObjectField(thiz, gSurfaceImageClassInfo.mPlanes); } isLocked = (planes != NULL); if (isLocked) { // no need to use fence here, as we it will be consumed by either cancel or queue buffer. status_t res = buffer->unlock(); if (res != OK) { jniThrowRuntimeException(env, "unlock buffer failed"); } ALOGV("Successfully unlocked the image"); } }
static jint Image_getFormat(JNIEnv* env, jobject thiz) { ALOGV("%s", __FUNCTION__); GraphicBuffer* buffer; Image_getNativeContext(env, thiz, &buffer, NULL); if (buffer == NULL) { jniThrowException(env, "java/lang/IllegalStateException", "Image is not initialized"); return 0; } return Image_getPixelFormat(env, buffer->getPixelFormat()); }
static GraphicBuffer* create_composible_buffer(int width, int height) { uint32_t bufferFlags = GraphicBuffer::USAGE_SW_WRITE_RARELY | GraphicBuffer::USAGE_HW_COMPOSER; GraphicBuffer* buffer = new GraphicBuffer(width, height, PIXEL_FORMAT_RGBA_8888, bufferFlags); status_t err = buffer->initCheck(); if (err) { LOGE("error creating GraphicBuffer: %s", strerror(-err)); return NULL; } Rect rect = buffer->getBounds(); LOGE("GraphicBuffer information"); LOGE("width : %d", buffer->getWidth()); LOGE("height: %d", buffer->getHeight()); LOGE("stride: %d", buffer->getStride()); LOGE("usage : 0x%08x", buffer->getUsage()); LOGE("format: %d", buffer->getPixelFormat()); LOGE("bounds: (%d,%d) - (%d,%d)", rect.left, rect.top, rect.right, rect.bottom); return buffer; }
static jint android_hardware_HardwareBuffer_getFormat(JNIEnv* env, jobject clazz, jlong nativeObject) { GraphicBuffer* buffer = GraphicBufferWrapper_to_GraphicBuffer(nativeObject); return static_cast<jint>(android_hardware_HardwareBuffer_convertFromPixelFormat( buffer->getPixelFormat())); }