int IOMXHWBuffer_Setup( void *window, int w, int h, int hal_format, int hw_usage ) { ANativeWindow *anw = (ANativeWindow *)window; int usage = 0; status_t err; CHECK_ANW(); LOGD( "IOMXHWBuffer_setup: %p, %d, %d, %X, %X\n", anw, w, h, hal_format, hw_usage ); usage |= hw_usage | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE; #if ANDROID_API >= 11 usage |= GRALLOC_USAGE_EXTERNAL_DISP; #endif err = native_window_set_usage( anw, usage ); CHECK_ERR(); #if ANDROID_API <= 13 err = native_window_set_buffers_geometry( anw, w, h, hal_format ); CHECK_ERR(); #else err = native_window_set_scaling_mode( anw, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW ); CHECK_ERR(); err = native_window_set_buffers_dimensions( anw, w, h ); CHECK_ERR(); err = native_window_set_buffers_format( anw, hal_format ); CHECK_ERR(); #endif return 0; }
status_t CameraClient::startPreviewMode() { LOG1("startPreviewMode"); status_t result = NO_ERROR; // if preview has been enabled, nothing needs to be done if (mHardware->previewEnabled()) { return NO_ERROR; } if (mPreviewWindow != 0) { native_window_set_scaling_mode(mPreviewWindow.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); native_window_set_buffers_transform(mPreviewWindow.get(), mOrientation); } #if defined(OMAP_ICS_CAMERA) || defined(OMAP_ENHANCEMENT_BURST_CAPTURE) disableMsgType(CAMERA_MSG_COMPRESSED_BURST_IMAGE); #endif mHardware->setPreviewWindow(mPreviewWindow); result = mHardware->startPreview(); return result; }
int PreviewRenderer::init() { int err = 0; ANativeWindow* anw = mSurface.get(); err = native_window_api_connect(anw, NATIVE_WINDOW_API_CPU); if (err) goto fail; err = native_window_set_usage( anw, GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_OFTEN); if (err) goto fail; err = native_window_set_buffer_count(anw, 3); if (err) goto fail; err = native_window_set_scaling_mode( anw, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); if (err) goto fail; err = native_window_set_buffers_geometry( anw, mWidth, mHeight, HAL_PIXEL_FORMAT_YV12); if (err) goto fail; err = native_window_set_buffers_transform(anw, 0); if (err) goto fail; fail: return err; }
CedarXSoftwareRenderer::CedarXSoftwareRenderer( const sp<ANativeWindow> &nativeWindow, const sp<MetaData> &meta) : mYUVMode(None), mNativeWindow(nativeWindow) { int32_t tmp; CHECK(meta->findInt32(kKeyColorFormat, &tmp)); mColorFormat = (OMX_COLOR_FORMATTYPE)tmp; //CHECK(meta->findInt32(kKeyScreenID, &screenID)); //CHECK(meta->findInt32(kKeyColorFormat, &halFormat)); CHECK(meta->findInt32(kKeyWidth, &mWidth)); CHECK(meta->findInt32(kKeyHeight, &mHeight)); int32_t rotationDegrees; if (!meta->findInt32(kKeyRotation, &rotationDegrees)) { rotationDegrees = 0; } int halFormat; size_t bufWidth, bufHeight; halFormat = HAL_PIXEL_FORMAT_YV12; bufWidth = mWidth; bufHeight = mHeight; CHECK(mNativeWindow != NULL); CHECK_EQ(0, native_window_set_usage( mNativeWindow.get(), GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP)); CHECK_EQ(0, native_window_set_scaling_mode( mNativeWindow.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)); // Width must be multiple of 32??? CHECK_EQ(0, native_window_set_buffers_geometry( mNativeWindow.get(), bufWidth, bufHeight, halFormat)); uint32_t transform; switch (rotationDegrees) { case 0: transform = 0; break; case 90: transform = HAL_TRANSFORM_ROT_90; break; case 180: transform = HAL_TRANSFORM_ROT_180; break; case 270: transform = HAL_TRANSFORM_ROT_270; break; default: transform = 0; break; } if (transform) { CHECK_EQ(0, native_window_set_buffers_transform( mNativeWindow.get(), transform)); } }
status_t CameraClient::setPreviewWindow(const sp<IBinder>& binder, const sp<ANativeWindow>& window) { Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; // return if no change in surface. if (binder == mSurface) { return NO_ERROR; } if (window != 0) { result = native_window_api_connect(window.get(), NATIVE_WINDOW_API_CAMERA); if (result != NO_ERROR) { ALOGE("native_window_api_connect failed: %s (%d)", strerror(-result), result); return result; } } // If preview has been already started, register preview buffers now. if (mHardware->previewEnabled()) { if (window != 0) { native_window_set_scaling_mode(window.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); native_window_set_buffers_transform(window.get(), mOrientation); result = mHardware->setPreviewWindow(window); } #ifdef QCOM_HARDWARE #ifndef NO_UPDATE_PREVIEW } else { if (window != 0) { native_window_set_buffers_transform(window.get(), mOrientation); } result = mHardware->setPreviewWindow(window); #endif #endif } if (result == NO_ERROR) { // Everything has succeeded. Disconnect the old window and remember the // new window. disconnectWindow(mPreviewWindow); mSurface = binder; mPreviewWindow = window; } else { // Something went wrong after we connected to the new window, so // disconnect here. disconnectWindow(window); } return result; }
ECode CMediaCodec::SetVideoScalingMode( /* [in] */ Int32 mode) { if (mCodec == NULL) { return E_ILLEGAL_STATE_EXCEPTION; } if (mode != NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW && mode != NATIVE_WINDOW_SCALING_MODE_SCALE_CROP) { Slogger::E(TAG, "mode error"); return E_INVALID_ARGUMENT; } if (mSurfaceTextureClient != NULL) { native_window_set_scaling_mode(mSurfaceTextureClient.get(),mode); } return NOERROR; }
status_t CameraService::Client::startPreviewMode() { LOG1("startPreviewMode"); status_t result = NO_ERROR; // if preview has been enabled, nothing needs to be done if (mHardware->previewEnabled()) { return NO_ERROR; } if (mPreviewWindow != 0) { native_window_set_scaling_mode(mPreviewWindow.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); native_window_set_buffers_transform(mPreviewWindow.get(), mOrientation); } mHardware->setPreviewWindow(mPreviewWindow); result = mHardware->startPreview(); return result; }
bool createNativeWindow(__u32 pixelformat) { mClient = new SurfaceComposerClient(); mSurfaceCtl = mClient->createSurface(String8("testsurface"), 800, 600, pixelformat, 0); // configure surface SurfaceComposerClient::openGlobalTransaction(); mSurfaceCtl->setLayer(100000); mSurfaceCtl->setPosition(100, 100); mSurfaceCtl->setSize(800, 600); SurfaceComposerClient::closeGlobalTransaction(); mSurface = mSurfaceCtl->getSurface(); mNativeWindow = mSurface; int bufWidth = 640; int bufHeight = 480; CHECK_EQ(0, native_window_set_usage( mNativeWindow.get(), GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP)); CHECK_EQ(0, native_window_set_scaling_mode( mNativeWindow.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)); CHECK_EQ(0, native_window_set_buffers_geometry( mNativeWindow.get(), bufWidth, bufHeight, pixelformat)); return true; }
status_t CameraService::Client::startPreviewMode() { LOG1("startPreviewMode"); status_t result = NO_ERROR; // if preview has been enabled, nothing needs to be done if (mHardware->previewEnabled()) { return NO_ERROR; } String8 params(mHardware->getParameters().flatten()); CameraParameters param(params); //param.getPreviewSize(&frameWidth, &frameHeight); if (mPreviewWindow != 0) { native_window_set_scaling_mode(mPreviewWindow.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); native_window_set_buffers_transform(mPreviewWindow.get(), mOrientation); } mHardware->setPreviewWindow(mPreviewWindow); result = mHardware->startPreview(); return result; }
SoftwareRenderer::SoftwareRenderer( const sp<ANativeWindow> &nativeWindow, const sp<MetaData> &meta) : mConverter(NULL), mYUVMode(None), mNativeWindow(nativeWindow) { int32_t tmp; CHECK(meta->findInt32(kKeyColorFormat, &tmp)); mColorFormat = (OMX_COLOR_FORMATTYPE)tmp; CHECK(meta->findInt32(kKeyWidth, &mWidth)); CHECK(meta->findInt32(kKeyHeight, &mHeight)); if (!meta->findRect( kKeyCropRect, &mCropLeft, &mCropTop, &mCropRight, &mCropBottom)) { mCropLeft = mCropTop = 0; mCropRight = mWidth - 1; mCropBottom = mHeight - 1; } mCropWidth = mCropRight - mCropLeft + 1; mCropHeight = mCropBottom - mCropTop + 1; int32_t rotationDegrees; if (!meta->findInt32(kKeyRotation, &rotationDegrees)) { rotationDegrees = 0; } int halFormat; size_t bufWidth, bufHeight; switch (mColorFormat) { case OMX_COLOR_FormatYUV420Planar: case OMX_TI_COLOR_FormatYUV420PackedSemiPlanar: { halFormat = HAL_PIXEL_FORMAT_YV12; bufWidth = (mCropWidth + 1) & ~1; bufHeight = (mCropHeight + 1) & ~1; if (ALIGN(bufWidth, 16) / 2 == ALIGN(bufWidth / 2, 16)) { break; } } default: halFormat = HAL_PIXEL_FORMAT_RGB_565; bufWidth = mCropWidth; bufHeight = mCropHeight; mConverter = new ColorConverter( mColorFormat, OMX_COLOR_Format16bitRGB565); CHECK(mConverter->isValid()); break; } CHECK(mNativeWindow != NULL); CHECK(mCropWidth > 0); CHECK(mCropHeight > 0); CHECK(mConverter == NULL || mConverter->isValid()); CHECK_EQ(0, native_window_set_usage( mNativeWindow.get(), GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP)); CHECK_EQ(0, native_window_set_scaling_mode( mNativeWindow.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)); // Width must be multiple of 32??? CHECK_EQ(0, native_window_set_buffers_geometry( mNativeWindow.get(), bufWidth, bufHeight, halFormat)); uint32_t transform; switch (rotationDegrees) { case 0: transform = 0; break; case 90: transform = HAL_TRANSFORM_ROT_90; break; case 180: transform = HAL_TRANSFORM_ROT_180; break; case 270: transform = HAL_TRANSFORM_ROT_270; break; default: transform = 0; break; } if (transform) { CHECK_EQ(0, native_window_set_buffers_transform( mNativeWindow.get(), transform)); } }
void SurfaceUtils::setScalingMode(int mode) { native_window_set_scaling_mode(mWindow, mode); }
void SoftwareRenderer::resetFormatIfChanged(const sp<AMessage> &format) { CHECK(format != NULL); int32_t colorFormatNew; CHECK(format->findInt32("color-format", &colorFormatNew)); int32_t widthNew, heightNew; CHECK(format->findInt32("stride", &widthNew)); CHECK(format->findInt32("slice-height", &heightNew)); int32_t cropLeftNew, cropTopNew, cropRightNew, cropBottomNew; if (!format->findRect( "crop", &cropLeftNew, &cropTopNew, &cropRightNew, &cropBottomNew)) { cropLeftNew = cropTopNew = 0; cropRightNew = widthNew - 1; cropBottomNew = heightNew - 1; } if (static_cast<int32_t>(mColorFormat) == colorFormatNew && mWidth == widthNew && mHeight == heightNew && mCropLeft == cropLeftNew && mCropTop == cropTopNew && mCropRight == cropRightNew && mCropBottom == cropBottomNew) { // Nothing changed, no need to reset renderer. return; } mColorFormat = static_cast<OMX_COLOR_FORMATTYPE>(colorFormatNew); mWidth = widthNew; mHeight = heightNew; mCropLeft = cropLeftNew; mCropTop = cropTopNew; mCropRight = cropRightNew; mCropBottom = cropBottomNew; mCropWidth = mCropRight - mCropLeft + 1; mCropHeight = mCropBottom - mCropTop + 1; int halFormat; size_t bufWidth, bufHeight; switch (mColorFormat) { case OMX_COLOR_FormatYUV420Planar: case OMX_TI_COLOR_FormatYUV420PackedSemiPlanar: case OMX_COLOR_FormatYUV420SemiPlanar: { if (!runningInEmulator()) { halFormat = HAL_PIXEL_FORMAT_YV12; bufWidth = (mCropWidth + 1) & ~1; bufHeight = (mCropHeight + 1) & ~1; break; } // fall through. } default: halFormat = HAL_PIXEL_FORMAT_RGB_565; bufWidth = mCropWidth; bufHeight = mCropHeight; mConverter = new ColorConverter( mColorFormat, OMX_COLOR_Format16bitRGB565); CHECK(mConverter->isValid()); break; } CHECK(mNativeWindow != NULL); CHECK(mCropWidth > 0); CHECK(mCropHeight > 0); CHECK(mConverter == NULL || mConverter->isValid()); CHECK_EQ(0, native_window_set_usage( mNativeWindow.get(), GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP)); CHECK_EQ(0, native_window_set_scaling_mode( mNativeWindow.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)); // Width must be multiple of 32??? CHECK_EQ(0, native_window_set_buffers_dimensions( mNativeWindow.get(), bufWidth, bufHeight)); CHECK_EQ(0, native_window_set_buffers_format( mNativeWindow.get(), halFormat)); // NOTE: native window uses extended right-bottom coordinate android_native_rect_t crop; crop.left = mCropLeft; crop.top = mCropTop; crop.right = mCropRight + 1; crop.bottom = mCropBottom + 1; ALOGV("setting crop: [%d, %d, %d, %d] for size [%zu, %zu]", crop.left, crop.top, crop.right, crop.bottom, bufWidth, bufHeight); CHECK_EQ(0, native_window_set_crop(mNativeWindow.get(), &crop)); int32_t rotationDegrees; if (!format->findInt32("rotation-degrees", &rotationDegrees)) { rotationDegrees = 0; } uint32_t transform; switch (rotationDegrees) { case 0: transform = 0; break; case 90: transform = HAL_TRANSFORM_ROT_90; break; case 180: transform = HAL_TRANSFORM_ROT_180; break; case 270: transform = HAL_TRANSFORM_ROT_270; break; default: transform = 0; break; } CHECK_EQ(0, native_window_set_buffers_transform( mNativeWindow.get(), transform)); }
CedarXSoftwareRenderer::CedarXSoftwareRenderer( const sp<ANativeWindow> &nativeWindow, const sp<MetaData> &meta) : mYUVMode(None), mNativeWindow(nativeWindow) { int32_t tmp; CHECK(meta->findInt32(kKeyColorFormat, &tmp)); //mColorFormat = (OMX_COLOR_FORMATTYPE)tmp; //CHECK(meta->findInt32(kKeyScreenID, &screenID)); //CHECK(meta->findInt32(kKeyColorFormat, &halFormat)); CHECK(meta->findInt32(kKeyWidth, &mWidth)); CHECK(meta->findInt32(kKeyHeight, &mHeight)); int32_t nVdecInitRotation; //clock wise. int32_t rotationDegrees; //anti-clock wise, if (!meta->findInt32(kKeyRotation, &nVdecInitRotation)) { LOGD("(f:%s, l:%d) find fail nVdecInitRotation[%d]", __FUNCTION__, __LINE__, nVdecInitRotation); rotationDegrees = 0; } else { switch(nVdecInitRotation) { case 0: { rotationDegrees = 0; break; } case 1: { rotationDegrees = 270; break; } case 2: { rotationDegrees = 180; break; } case 3: { rotationDegrees = 90; break; } default: { LOGW("(f:%s, l:%d) nInitRotation=%d", __FUNCTION__, __LINE__, nVdecInitRotation); rotationDegrees = 0; break; } } } meta->findInt32(kKey3dDoubleStream, &m3dModeDoubleStreamFlag); int GpuBufHeight_num = 0; int halFormat; size_t bufWidth, bufHeight; size_t nGpuBufWidth, nGpuBufHeight; if(0 == m3dModeDoubleStreamFlag) { GpuBufHeight_num = 1; } else { LOGD("(f:%s, l:%d) be careful for 3d double stream!", __FUNCTION__, __LINE__); GpuBufHeight_num = 2; } halFormat = HAL_PIXEL_FORMAT_YV12; bufWidth = mWidth; bufHeight = mHeight; if(bufWidth != ((mWidth + 15) & ~15)) { LOGW("(f:%s, l:%d) bufWidth[%d]!=display_width[%d]", __FUNCTION__, __LINE__, ((mWidth + 15) & ~15), mWidth); } if(bufHeight != ((mHeight + 15) & ~15)) { LOGW("(f:%s, l:%d) bufHeight[%d]!=display_height[%d]", __FUNCTION__, __LINE__, ((mHeight + 15) & ~15), mHeight); } CHECK(mNativeWindow != NULL); int usage = 0; meta->findInt32(kKeyIsDRM, &usage); if(usage) { LOGV("protected video"); usage = GRALLOC_USAGE_PROTECTED; } usage |= GRALLOC_USAGE_SW_READ_NEVER /*| GRALLOC_USAGE_SW_WRITE_OFTEN*/ | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP; CHECK_EQ(0, native_window_set_usage( mNativeWindow.get(), usage)); CHECK_EQ(0, native_window_set_scaling_mode( mNativeWindow.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)); // Width must be multiple of 32??? nGpuBufWidth = mWidth; nGpuBufHeight = mHeight; #if (defined(__CHIP_VERSION_F23) || (defined(__CHIP_VERSION_F51))) #if (1 == ADAPT_A10_GPU_RENDER) nGpuBufWidth = (mWidth + 15) & ~15; //A10's GPU has a bug, we can avoid it if(nGpuBufHeight%8 != 0) { LOGD("(f:%s, l:%d) original gpu buf align_width[%d], height[%d]mod8 = %d", __FUNCTION__, __LINE__, nGpuBufWidth, nGpuBufHeight, nGpuBufHeight%8); if((nGpuBufWidth*nGpuBufHeight)%256 != 0) { // e:\videofile\test_stream\avi, 800*450 LOGW("(f:%s, l:%d) original gpu buf align_width[%d]*height[%d]mod1024 = %d", __FUNCTION__, __LINE__, nGpuBufWidth, nGpuBufHeight, (nGpuBufWidth*nGpuBufHeight)%1024); nGpuBufHeight = (nGpuBufHeight+7)&~7; LOGW("(f:%s, l:%d) change gpu buf height to [%d]", __FUNCTION__, __LINE__, nGpuBufHeight); } } nGpuBufWidth = mWidth; //restore GpuBufWidth to mWidth; #endif #elif defined(__CHIP_VERSION_F33) #if (1 == ADAPT_A31_GPU_RENDER) //A31 GPU rect width should 8 align. if(mWidth%8 != 0) { nGpuBufWidth = (mWidth + 7) & ~7; LOGD("(f:%s, l:%d) A31 gpuBufWidth[%d]mod16=[%d] ,should 8 align, change to [%d]", __FUNCTION__, __LINE__, mWidth, mWidth%8, nGpuBufWidth); } #endif #else #error "Unknown chip type!" #endif CHECK_EQ(0, native_window_set_buffers_geometry( mNativeWindow.get(), //(bufWidth + 15) & ~15, //(bufHeight+ 15) & ~15, //(bufWidth + 15) & ~15, //bufHeight, //bufWidth, //bufHeight, nGpuBufWidth, nGpuBufHeight * GpuBufHeight_num, halFormat)); uint32_t transform; switch (rotationDegrees) { case 0: transform = 0; break; case 90: transform = HAL_TRANSFORM_ROT_90; break; case 180: transform = HAL_TRANSFORM_ROT_180; break; case 270: transform = HAL_TRANSFORM_ROT_270; break; default: transform = 0; break; } if (transform) { LOGD("(f:%s, l:%d) transform[%d]", __FUNCTION__, __LINE__, transform); CHECK_EQ(0, native_window_set_buffers_transform( mNativeWindow.get(), transform)); } Rect crop; crop.left = 0; crop.top = 0; crop.right = bufWidth; crop.bottom = bufHeight; mNativeWindow->perform(mNativeWindow.get(), NATIVE_WINDOW_SET_CROP, &crop); }
void JMediaCodec::setVideoScalingMode(int mode) { if (mSurfaceTextureClient != NULL) { native_window_set_scaling_mode(mSurfaceTextureClient.get(), mode); } }
status_t setNativeWindowSizeFormatAndUsage( ANativeWindow *nativeWindow /* nonnull */, int width, int height, int format, int rotation, int usage) { status_t err = native_window_set_buffers_dimensions(nativeWindow, width, height); if (err != NO_ERROR) { ALOGE("native_window_set_buffers_dimensions failed: %s (%d)", strerror(-err), -err); return err; } err = native_window_set_buffers_format(nativeWindow, format); if (err != NO_ERROR) { ALOGE("native_window_set_buffers_format failed: %s (%d)", strerror(-err), -err); return err; } int transform = 0; if ((rotation % 90) == 0) { switch ((rotation / 90) & 3) { case 1: transform = HAL_TRANSFORM_ROT_90; break; case 2: transform = HAL_TRANSFORM_ROT_180; break; case 3: transform = HAL_TRANSFORM_ROT_270; break; default: transform = 0; break; } } err = native_window_set_buffers_transform(nativeWindow, transform); if (err != NO_ERROR) { ALOGE("native_window_set_buffers_transform failed: %s (%d)", strerror(-err), -err); return err; } // Make sure to check whether either Stagefright or the video decoder // requested protected buffers. if (usage & GRALLOC_USAGE_PROTECTED) { // Verify that the ANativeWindow sends images directly to // SurfaceFlinger. int queuesToNativeWindow = 0; err = nativeWindow->query( nativeWindow, NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER, &queuesToNativeWindow); if (err != NO_ERROR) { ALOGE("error authenticating native window: %s (%d)", strerror(-err), -err); return err; } if (queuesToNativeWindow != 1) { ALOGE("native window could not be authenticated"); return PERMISSION_DENIED; } } int consumerUsage = 0; err = nativeWindow->query(nativeWindow, NATIVE_WINDOW_CONSUMER_USAGE_BITS, &consumerUsage); if (err != NO_ERROR) { ALOGW("failed to get consumer usage bits. ignoring"); err = NO_ERROR; } int finalUsage = usage | consumerUsage; ALOGV("gralloc usage: %#x(producer) + %#x(consumer) = %#x", usage, consumerUsage, finalUsage); err = native_window_set_usage(nativeWindow, finalUsage); if (err != NO_ERROR) { ALOGE("native_window_set_usage failed: %s (%d)", strerror(-err), -err); return err; } err = native_window_set_scaling_mode( nativeWindow, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); if (err != NO_ERROR) { ALOGE("native_window_set_scaling_mode failed: %s (%d)", strerror(-err), -err); return err; } ALOGD("set up nativeWindow %p for %dx%d, color %#x, rotation %d, usage %#x", nativeWindow, width, height, format, rotation, finalUsage); return NO_ERROR; }
bool_e anativewindow_allocate(anativewindow_t *anw, uint32_t buffer_width, uint32_t buffer_height, int32_t numBuffers, int32_t format, bool flipH) { if (format != ANW_NV12_FORMAT) return false_e; if (anw) { status_t status = 0; anw->m_format = format; anw->m_usage = GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_SW_READ_OFTEN | // Non-cached ? If you use RARELY it will complain GRALLOC_USAGE_SW_WRITE_NEVER; // can't access from UVA anw->m_numBuffers = numBuffers; anw->m_width = buffer_width; anw->m_height = buffer_height; anw->m_native_buffers = (ANativeWindowBuffer **)calloc(numBuffers, sizeof(ANativeWindowBuffer *)); DVP_PRINT(DVP_ZONE_VIDEO, "Created %u pointers in native array %p\n", numBuffers, anw->m_native_buffers); if (anw->m_native_buffers == NULL) { return false_e; } // connect to the native window API status = native_window_api_connect(anw->m_window.get(), NATIVE_WINDOW_API_CAMERA); ANW_ERROR(status,"CONNECT"); // set the scaling mode of the windows status = native_window_set_scaling_mode(anw->m_window.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); ANW_ERROR(status,"SCALING"); #if defined(BLAZE_TABLET) && defined(ICS) // set the layout of the buffer status = native_window_set_buffers_layout(anw->m_window.get(), NATIVE_WINDOW_BUFFERS_LAYOUT_PROGRESSIVE); // progressive ANW_ERROR(status,"LAYOUT"); #endif // set the format of the buffer status = native_window_set_buffers_format(anw->m_window.get(), anw->m_format); ANW_ERROR(status,"FORMAT"); // setup the dimensions status = native_window_set_buffers_dimensions(anw->m_window.get(), anw->m_width, anw->m_height); ANW_ERROR(status,"DIM"); if (flipH) { // set the horizontal flip status = native_window_set_buffers_transform(anw->m_window.get(), NATIVE_WINDOW_TRANSFORM_FLIP_H); ANW_ERROR(status,"TRANSFORM FLIP HORIZONTAL"); } // set the usage of the GRALLOC buffers status = native_window_set_usage(anw->m_window.get(), anw->m_usage); if (status < 0 ) { DVP_PRINT(DVP_ZONE_ERROR, "%s[%u] USAGE status = %d (0x%08x)\n", __FUNCTION__, __LINE__, status, anw->m_usage); } // set the number of buffers required. status = native_window_set_buffer_count(anw->m_window.get(), anw->m_numBuffers); ANW_ERROR(status,"COUNT"); // get the number of dequeueable buffers status = anw->m_window->query(anw->m_window.get(), NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, (int*)&anw->m_nonqueue); ANW_ERROR(status,"QUERY NONQUEUE"); for (uint32_t n = 0; n < anw->m_numBuffers; n++) { status = anw->m_window->dequeueBuffer(anw->m_window.get(), &anw->m_native_buffers[n]); if (status != 0) { DVP_PRINT(DVP_ZONE_ERROR, "%s[%u] %s status = %d\n", __FUNCTION__, __LINE__, "Failed window buffer dequeue!", status); \ return false_e; } if (anw->m_native_buffers[n]) { native_handle_t *hdl = (native_handle_t *)anw->m_native_buffers[n]->handle; hdl = hdl; // warnings DVP_PRINT(DVP_ZONE_VIDEO, "ANativeBuffer %p => dim %dx%d stride %d usage %d format %d handle %p numFds=%u\n", anw->m_native_buffers[n], anw->m_native_buffers[n]->width, anw->m_native_buffers[n]->height, anw->m_native_buffers[n]->stride, anw->m_native_buffers[n]->usage, anw->m_native_buffers[n]->format, anw->m_native_buffers[n]->handle, hdl->numFds); } } return true_e; } return false_e; }
status_t Camera3OutputStream::configureQueueLocked() { status_t res; mTraceFirstBuffer = true; if ((res = Camera3IOStreamBase::configureQueueLocked()) != OK) { return res; } ALOG_ASSERT(mConsumer != 0, "mConsumer should never be NULL"); // Configure consumer-side ANativeWindow interface res = native_window_api_connect(mConsumer.get(), NATIVE_WINDOW_API_CAMERA); if (res != OK) { ALOGE("%s: Unable to connect to native window for stream %d", __FUNCTION__, mId); return res; } res = native_window_set_usage(mConsumer.get(), camera3_stream::usage); if (res != OK) { ALOGE("%s: Unable to configure usage %08x for stream %d", __FUNCTION__, camera3_stream::usage, mId); return res; } res = native_window_set_scaling_mode(mConsumer.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); if (res != OK) { ALOGE("%s: Unable to configure stream scaling: %s (%d)", __FUNCTION__, strerror(-res), res); return res; } if (mMaxSize == 0) { // For buffers of known size res = native_window_set_buffers_dimensions(mConsumer.get(), camera3_stream::width, camera3_stream::height); } else { // For buffers with bounded size res = native_window_set_buffers_dimensions(mConsumer.get(), mMaxSize, 1); } if (res != OK) { ALOGE("%s: Unable to configure stream buffer dimensions" " %d x %d (maxSize %zu) for stream %d", __FUNCTION__, camera3_stream::width, camera3_stream::height, mMaxSize, mId); return res; } res = native_window_set_buffers_format(mConsumer.get(), camera3_stream::format); if (res != OK) { ALOGE("%s: Unable to configure stream buffer format %#x for stream %d", __FUNCTION__, camera3_stream::format, mId); return res; } int maxConsumerBuffers; res = mConsumer->query(mConsumer.get(), NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &maxConsumerBuffers); if (res != OK) { ALOGE("%s: Unable to query consumer undequeued" " buffer count for stream %d", __FUNCTION__, mId); return res; } ALOGV("%s: Consumer wants %d buffers, HAL wants %d", __FUNCTION__, maxConsumerBuffers, camera3_stream::max_buffers); if (camera3_stream::max_buffers == 0) { ALOGE("%s: Camera HAL requested max_buffer count: %d, requires at least 1", __FUNCTION__, camera3_stream::max_buffers); return INVALID_OPERATION; } mTotalBufferCount = maxConsumerBuffers + camera3_stream::max_buffers; mHandoutTotalBufferCount = 0; mFrameCount = 0; mLastTimestamp = 0; res = native_window_set_buffer_count(mConsumer.get(), mTotalBufferCount); if (res != OK) { ALOGE("%s: Unable to set buffer count for stream %d", __FUNCTION__, mId); return res; } res = native_window_set_buffers_transform(mConsumer.get(), mTransform); if (res != OK) { ALOGE("%s: Unable to configure stream transform to %x: %s (%d)", __FUNCTION__, mTransform, strerror(-res), res); } return OK; }
SoftwareRenderer::SoftwareRenderer( const sp<ANativeWindow> &nativeWindow, const sp<MetaData> &meta) : mConverter(NULL), mYUVMode(None), mNativeWindow(nativeWindow) { int32_t tmp; CHECK(meta->findInt32(kKeyColorFormat, &tmp)); mColorFormat = (OMX_COLOR_FORMATTYPE)tmp; CHECK(meta->findInt32(kKeyWidth, &mWidth)); CHECK(meta->findInt32(kKeyHeight, &mHeight)); if (!meta->findRect( kKeyCropRect, &mCropLeft, &mCropTop, &mCropRight, &mCropBottom)) { mCropLeft = mCropTop = 0; mCropRight = mWidth - 1; mCropBottom = mHeight - 1; } mCropWidth = mCropRight - mCropLeft + 1; mCropHeight = mCropBottom - mCropTop + 1; int32_t rotationDegrees; if (!meta->findInt32(kKeyRotation, &rotationDegrees)) { rotationDegrees = 0; } int halFormat; size_t bufWidth, bufHeight; switch (mColorFormat) { case OMX_COLOR_FormatYUV420Planar: case OMX_TI_COLOR_FormatYUV420PackedSemiPlanar: { if (!runningInEmulator()) { halFormat = HAL_PIXEL_FORMAT_YV12; bufWidth = (mCropWidth + 1) & ~1; bufHeight = (mCropHeight + 1) & ~1; break; } // fall through. } #ifdef QCOM_LEGACY_OMX case OMX_QCOM_COLOR_FormatYVU420SemiPlanar: { halFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; bufWidth = (mCropWidth + 1) & ~1; bufHeight = (mCropHeight + 1) & ~1; mAlign = ((mWidth + 15) & -16) * ((mHeight + 15) & -16); break; } #endif default: halFormat = HAL_PIXEL_FORMAT_RGB_565; bufWidth = mCropWidth; bufHeight = mCropHeight; mConverter = new ColorConverter( mColorFormat, OMX_COLOR_Format16bitRGB565); CHECK(mConverter->isValid()); break; } ALOGI("Buffer color format: 0x%X", mColorFormat); ALOGI("Video params: mWidth: %d, mHeight: %d, mCropWidth: %d, mCropHeight: %d, mCropTop: %d, mCropLeft: %d", mWidth, mHeight, mCropWidth, mCropHeight, mCropTop, mCropLeft); CHECK(mNativeWindow != NULL); CHECK(mCropWidth > 0); CHECK(mCropHeight > 0); CHECK(mConverter == NULL || mConverter->isValid()); #ifdef EXYNOS4_ENHANCEMENTS CHECK_EQ(0, native_window_set_usage( mNativeWindow.get(), GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP | GRALLOC_USAGE_HW_FIMC1 | GRALLOC_USAGE_HWC_HWOVERLAY)); #else CHECK_EQ(0, native_window_set_usage( mNativeWindow.get(), GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP #ifdef QCOM_LEGACY_OMX | GRALLOC_USAGE_PRIVATE_ADSP_HEAP | GRALLOC_USAGE_PRIVATE_UNCACHED #endif )); #endif CHECK_EQ(0, native_window_set_scaling_mode( mNativeWindow.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)); // Width must be multiple of 32??? CHECK_EQ(0, native_window_set_buffers_geometry( mNativeWindow.get(), bufWidth, bufHeight, halFormat)); uint32_t transform; switch (rotationDegrees) { case 0: transform = 0; break; case 90: transform = HAL_TRANSFORM_ROT_90; break; case 180: transform = HAL_TRANSFORM_ROT_180; break; case 270: transform = HAL_TRANSFORM_ROT_270; break; default: transform = 0; break; } if (transform) { CHECK_EQ(0, native_window_set_buffers_transform( mNativeWindow.get(), transform)); } }
void FakeSurfaceComposer::captureScreenImp(const sp<IGraphicBufferProducer>& producer, uint32_t reqWidth, uint32_t reqHeight, const sp<GraphicProducerWrapper>& wrapper) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(wrapper.get()); RefPtr<nsScreenGonk> screen = nsScreenManagerGonk::GetPrimaryScreen(); // get screen geometry nsIntRect screenBounds = screen->GetNaturalBounds().ToUnknownRect(); const uint32_t hw_w = screenBounds.width; const uint32_t hw_h = screenBounds.height; if (reqWidth > hw_w || reqHeight > hw_h) { ALOGE("size mismatch (%d, %d) > (%d, %d)", reqWidth, reqHeight, hw_w, hw_h); static_cast<GraphicProducerWrapper*>(producer->asBinder().get())->exit(BAD_VALUE); return; } reqWidth = (!reqWidth) ? hw_w : reqWidth; reqHeight = (!reqHeight) ? hw_h : reqHeight; nsScreenGonk* screenPtr = screen.forget().take(); nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([screenPtr, reqWidth, reqHeight, producer, wrapper]() { // create a surface (because we're a producer, and we need to // dequeue/queue a buffer) sp<Surface> sur = new Surface(producer); ANativeWindow* window = sur.get(); if (native_window_api_connect(window, NATIVE_WINDOW_API_EGL) != NO_ERROR) { static_cast<GraphicProducerWrapper*>(producer->asBinder().get())->exit(BAD_VALUE); NS_ReleaseOnMainThread(screenPtr); return; } uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE; int err = 0; err = native_window_set_buffers_dimensions(window, reqWidth, reqHeight); err |= native_window_set_scaling_mode(window, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); err |= native_window_set_buffers_format(window, HAL_PIXEL_FORMAT_RGBA_8888); err |= native_window_set_usage(window, usage); status_t result = NO_ERROR; if (err == NO_ERROR) { ANativeWindowBuffer* buffer; result = native_window_dequeue_buffer_and_wait(window, &buffer); if (result == NO_ERROR) { nsresult rv = screenPtr->MakeSnapshot(buffer); if (rv != NS_OK) { result = INVALID_OPERATION; } window->queueBuffer(window, buffer, -1); } } else { result = BAD_VALUE; } native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); static_cast<GraphicProducerWrapper*>(producer->asBinder().get())->exit(result); NS_ReleaseOnMainThread(screenPtr); }); mozilla::layers::CompositorParent::CompositorLoop()->PostTask( FROM_HERE, new RunnableCallTask(runnable)); }