extern "C" int fbdevws_IsValidDisplay(EGLNativeDisplayType display) { if (__sync_fetch_and_add(&inited,1)==0) { int err; err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **) &gralloc); if (gralloc==NULL) { fprintf(stderr, "failed to get gralloc module: (%s)\n",strerror(-err)); assert(0); } err = framebuffer_open((hw_module_t *) gralloc, &framebuffer); if (err) { fprintf(stderr, "ERROR: failed to open framebuffer: (%s)\n",strerror(-err)); assert(0); } printf("** framebuffer_open: status=(%s) format=x%x", strerror(-err), framebuffer->format); err = gralloc_open((const hw_module_t *) gralloc, &alloc); if (err) { fprintf(stderr, "ERROR: failed to open gralloc: (%s)\n",strerror(-err)); assert(0); } printf("** gralloc_open %p status=%s\n", gralloc, strerror(-err)); eglplatformcommon_init(gralloc); } return display == EGL_DEFAULT_DISPLAY; }
// Opens Framebuffer device static void openFramebufferDevice(hwc_context_t *ctx) { hw_module_t const *module; if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { framebuffer_open(module, &(ctx->mFbDev)); } }
FramebufferNativeWindow::FramebufferNativeWindow() : BASE(), fbDev(0), grDev(0), mUpdateOnDemand(false) { hw_module_t const* module; if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { int stride; int err; err = framebuffer_open(module, &fbDev); LOGE_IF(err, "couldn't open framebuffer HAL (%s)", strerror(-err)); err = gralloc_open(module, &grDev); LOGE_IF(err, "couldn't open gralloc HAL (%s)", strerror(-err)); // bail out if we can't initialize the modules if (!fbDev || !grDev) return; mUpdateOnDemand = (fbDev->setUpdateRect != 0); // initialize the buffer FIFO mNumBuffers = 2; mNumFreeBuffers = 2; mBufferHead = mNumBuffers-1; buffers[0] = new NativeBuffer( fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB); buffers[1] = new NativeBuffer( fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB); err = grDev->alloc(grDev, fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB, &buffers[0]->handle, &buffers[0]->stride); LOGE_IF(err, "fb buffer 0 allocation failed w=%d, h=%d, err=%s", fbDev->width, fbDev->height, strerror(-err)); err = grDev->alloc(grDev, fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB, &buffers[1]->handle, &buffers[1]->stride); LOGE_IF(err, "fb buffer 1 allocation failed w=%d, h=%d, err=%s", fbDev->width, fbDev->height, strerror(-err)); const_cast<uint32_t&>(android_native_window_t::flags) = fbDev->flags; const_cast<float&>(android_native_window_t::xdpi) = fbDev->xdpi; const_cast<float&>(android_native_window_t::ydpi) = fbDev->ydpi; const_cast<int&>(android_native_window_t::minSwapInterval) = fbDev->minSwapInterval; const_cast<int&>(android_native_window_t::maxSwapInterval) = fbDev->maxSwapInterval; } else { LOGE("Couldn't get gralloc module"); } android_native_window_t::setSwapInterval = setSwapInterval; android_native_window_t::dequeueBuffer = dequeueBuffer; android_native_window_t::lockBuffer = lockBuffer; android_native_window_t::queueBuffer = queueBuffer; android_native_window_t::query = query; android_native_window_t::perform = perform; }
FbDevice::FbDevice(){ hw_module_t const *module; if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { framebuffer_open(module, &sFb); } else { ALOGE("FATAL ERROR: framebuffer open failed."); } }
bool Hwcomposer::initialize() { int err; log.d("initialize"); // open frame buffer device hw_module_t const* module; err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); if (err) { log.e("Hwcomposer::initialize: failed to load gralloc module, %d", err); return false; } IMG_gralloc_module_public_t *imgGrallocModule; imgGrallocModule = (IMG_gralloc_module_public_t*)module; // open frame buffer device err = framebuffer_open(module, (framebuffer_device_t**)&mFBDev); if (err) { log.e("Hwcomposer::initialize: failed to open frame buffer device, %d", err); return false; } mFBDev->bBypassPost = 1; // create display plane manager mPlaneManager = createDisplayPlaneManager(); if (!mPlaneManager || !mPlaneManager->initialize()) { log.e("initialize: failed to create display plane manager"); goto dpm_create_err; } // create display device for (int i = 0; i < IDisplayDevice::DEVICE_COUNT; i++) { IDisplayDevice *device = createDisplayDevice(i, *mPlaneManager); if (!device || !device->initialize()) { log.e("initialize: failed to create device %d", i); continue; } // add this device mDisplayDevices.insertAt(device, i, 1); } mInitialized = true; return true; device_create_err: for (size_t i = 0; i < mDisplayDevices.size(); i++) { IDisplayDevice *device = mDisplayDevices.itemAt(i); delete device; } dpm_create_err: framebuffer_close((framebuffer_device_t*)mFBDev); mInitialized = false; return false; }
void hybris_gralloc_initialize(int framebuffer) { if (version == -1) { if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const struct hw_module_t **)&gralloc_hardware_module) == 0) { #if HAS_GRALLOC1_HEADER if ((gralloc1_open(gralloc_hardware_module, &gralloc1_device) == 0) && (gralloc1_device != NULL)) { // success gralloc1_init(); version = 1; atexit(hybris_gralloc_deinitialize); } else #endif if (framebuffer) { if (framebuffer_open(gralloc_hardware_module, &framebuffer_device) == 0) { if ((gralloc_open(gralloc_hardware_module, &gralloc0_alloc) == 0) && gralloc0_alloc != NULL) { // success gralloc0_module = (struct gralloc_module_t*)gralloc_hardware_module; version = 0; atexit(hybris_gralloc_deinitialize); } else { fprintf(stderr, "failed to open the gralloc 0 module (framebuffer was requested therefore defaulted to version 0)\n"); assert(NULL); } } else { fprintf(stderr, "failed to open the framebuffer module\n"); assert(NULL); } } else if ((gralloc_open(gralloc_hardware_module, &gralloc0_alloc) == 0) && gralloc0_alloc != NULL) { // success gralloc0_module = (struct gralloc_module_t*)gralloc_hardware_module; version = 0; atexit(hybris_gralloc_deinitialize); } else { // fail framebuffer_device = NULL; #if HAS_GRALLOC1_HEADER gralloc1_device = NULL; #endif version = -2; fprintf(stderr, "failed to open gralloc module with both version 0 and 1 methods\n"); hybris_gralloc_deinitialize(); assert(NULL); } } else { fprintf(stderr, "failed to find/load gralloc module\n"); assert(NULL); } } else { // shouldn't reach here. assert(NULL); } }
extern "C" int fbdevws_IsValidDisplay(EGLNativeDisplayType display) { if (__sync_fetch_and_add(&inited,1)==0) { hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **) &gralloc); int err = framebuffer_open((hw_module_t *) gralloc, &framebuffer); printf("** open framebuffer HAL (%s) format x%x\n", strerror(-err), framebuffer->format); err = gralloc_open((const hw_module_t *) gralloc, &alloc); printf("** got gralloc %p err:%s\n", gralloc, strerror(-err)); eglplatformcommon_init(gralloc); } return display == EGL_DEFAULT_DISPLAY; }
extern "C" int ws_fbdev_IsValidDisplay(EGLNativeDisplayType display) { if (inited == 0) { hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **) &gralloc); int err = framebuffer_open((hw_module_t *) gralloc, &framebuffer); printf("open framebuffer HAL (%s) format %i", strerror(-err), framebuffer->format); err = gralloc_open((const hw_module_t *) gralloc, &alloc); printf("got gralloc %p err:%s\n", gralloc, strerror(-err)); inited = 1; } return display == EGL_DEFAULT_DISPLAY; }
// Opens Framebuffer device static void openFramebufferDevice(hwc_context_t *ctx) { hw_module_t const *module; if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { framebuffer_open(module, &(ctx->mFbDev)); private_module_t* m = reinterpret_cast<private_module_t*>( ctx->mFbDev->common.module); //xres, yres may not be 32 aligned ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = m->info.xres; ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = m->info.yres; ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = ctx->mFbDev->xdpi; ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ctx->mFbDev->ydpi; ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = 1000000000l / ctx->mFbDev->fps; ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = openFb(HWC_DISPLAY_PRIMARY); } }
std::shared_ptr<framebuffer_device_t> mga::ResourceFactory::create_fb_native_device() const { hw_module_t const* module; framebuffer_device_t* fbdev_raw; auto rc = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); if ((rc != 0) || (module == nullptr) || (framebuffer_open(module, &fbdev_raw) != 0) ) { BOOST_THROW_EXCEPTION(std::runtime_error("display factory cannot create fb display")); } return std::shared_ptr<framebuffer_device_t>(fbdev_raw, [](struct framebuffer_device_t* fbdevice) { fbdevice->common.close((hw_device_t*) fbdevice); }); }
int main (int argc, char **argv) { int i; for (i = 1; i < argc; i++) { if (!strcmp ("--verbose", argv[i]) || !strcmp ("-v", argv[i])) { Verbose = 1; continue; } if (!strcmp ("--multiblit", argv[i])) { WantMultiBlit = 1; continue; } if (!strcmp ("--cycles", argv[i])) { if (++i>=argc) usage (); TotalCycles = atoi(argv[i]); if (TotalCycles < 1) usage(); continue; } usage(); } if (framebuffer_open(NULL, NULL) == -1) { perror("framebuffer_open failed."); exit(0); } framebuffer_blit(); framebuffer_close(); return 0; }
FramebufferNativeWindow::FramebufferNativeWindow() : BASE(), fbDev(0), grDev(0), mUpdateOnDemand(false) { hw_module_t const* module; if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { int stride; int err; int i; err = framebuffer_open(module, &fbDev); ALOGE_IF(err, "couldn't open framebuffer HAL (%s)", strerror(-err)); err = gralloc_open(module, &grDev); ALOGE_IF(err, "couldn't open gralloc HAL (%s)", strerror(-err)); // bail out if we can't initialize the modules if (!fbDev || !grDev) return; mUpdateOnDemand = (fbDev->setUpdateRect != 0); // initialize the buffer FIFO if(fbDev->numFramebuffers >= MIN_NUM_FRAME_BUFFERS && fbDev->numFramebuffers <= MAX_NUM_FRAME_BUFFERS){ mNumBuffers = fbDev->numFramebuffers; } else { mNumBuffers = MIN_NUM_FRAME_BUFFERS; } mNumFreeBuffers = mNumBuffers; mBufferHead = mNumBuffers-1; /* * This does not actually change the framebuffer format. It merely * fakes this format to surfaceflinger so that when it creates * framebuffer surfaces it will use this format. It's really a giant * HACK to allow interworking with buggy gralloc+GPU driver * implementations. You should *NEVER* need to set this for shipping * devices. */ #ifdef FRAMEBUFFER_FORCE_FORMAT *((uint32_t *)&fbDev->format) = FRAMEBUFFER_FORCE_FORMAT; #endif for (i = 0; i < mNumBuffers; i++) { buffers[i] = new NativeBuffer( fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB); } for (i = 0; i < mNumBuffers; i++) { err = grDev->alloc(grDev, fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB, &buffers[i]->handle, &buffers[i]->stride); ALOGE_IF(err, "fb buffer %d allocation failed w=%d, h=%d, err=%s", i, fbDev->width, fbDev->height, strerror(-err)); if (err) { mNumBuffers = i; mNumFreeBuffers = i; mBufferHead = mNumBuffers-1; break; } } const_cast<uint32_t&>(ANativeWindow::flags) = fbDev->flags; const_cast<float&>(ANativeWindow::xdpi) = fbDev->xdpi; const_cast<float&>(ANativeWindow::ydpi) = fbDev->ydpi; const_cast<int&>(ANativeWindow::minSwapInterval) = fbDev->minSwapInterval; const_cast<int&>(ANativeWindow::maxSwapInterval) = fbDev->maxSwapInterval; } else { ALOGE("Couldn't get gralloc module"); } ANativeWindow::setSwapInterval = setSwapInterval; ANativeWindow::dequeueBuffer = dequeueBuffer; ANativeWindow::lockBuffer = lockBuffer; ANativeWindow::queueBuffer = queueBuffer; ANativeWindow::query = query; ANativeWindow::perform = perform; ANativeWindow::cancelBuffer = NULL; }
FramebufferNativeWindow::FramebufferNativeWindow() : BASE(), fbDev(0), grDev(0), mUpdateOnDemand(false) { hw_module_t const* module; if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { int stride; int err; #ifdef OMAP_ENHANCEMENT int i; #endif err = framebuffer_open(module, &fbDev); LOGE_IF(err, "couldn't open framebuffer HAL (%s)", strerror(-err)); err = gralloc_open(module, &grDev); LOGE_IF(err, "couldn't open gralloc HAL (%s)", strerror(-err)); // bail out if we can't initialize the modules if (!fbDev || !grDev) return; mUpdateOnDemand = (fbDev->setUpdateRect != 0); // initialize the buffer FIFO #ifdef OMAP_ENHANCEMENT mNumBuffers = NUM_FRAME_BUFFERS; mNumFreeBuffers = NUM_FRAME_BUFFERS; #else mNumBuffers = 2; mNumFreeBuffers = 2; #endif mBufferHead = mNumBuffers-1; #ifdef OMAP_ENHANCEMENT for(i = 0; i < NUM_FRAME_BUFFERS; i++){ buffers[i] = new NativeBuffer( fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB); } for(i = 0; i < NUM_FRAME_BUFFERS; i++){ err = grDev->alloc(grDev, fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB, &buffers[i]->handle, &buffers[i]->stride); LOGE_IF(err, "fb buffer %d allocation failed w=%d, h=%d, err=%s", i, fbDev->width, fbDev->height, strerror(-err)); if(err){ mNumBuffers = i; mNumFreeBuffers = i; mBufferHead = mNumBuffers-1; break; } } #else buffers[0] = new NativeBuffer( fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB); buffers[1] = new NativeBuffer( fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB); err = grDev->alloc(grDev, fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB, &buffers[0]->handle, &buffers[0]->stride); LOGE_IF(err, "fb buffer 0 allocation failed w=%d, h=%d, err=%s", fbDev->width, fbDev->height, strerror(-err)); err = grDev->alloc(grDev, fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB, &buffers[1]->handle, &buffers[1]->stride); LOGE_IF(err, "fb buffer 1 allocation failed w=%d, h=%d, err=%s", fbDev->width, fbDev->height, strerror(-err)); #endif const_cast<uint32_t&>(ANativeWindow::flags) = fbDev->flags; const_cast<float&>(ANativeWindow::xdpi) = fbDev->xdpi; const_cast<float&>(ANativeWindow::ydpi) = fbDev->ydpi; const_cast<int&>(ANativeWindow::minSwapInterval) = fbDev->minSwapInterval; const_cast<int&>(ANativeWindow::maxSwapInterval) = fbDev->maxSwapInterval; } else { LOGE("Couldn't get gralloc module"); } ANativeWindow::setSwapInterval = setSwapInterval; ANativeWindow::dequeueBuffer = dequeueBuffer; ANativeWindow::lockBuffer = lockBuffer; ANativeWindow::queueBuffer = queueBuffer; ANativeWindow::cancelBuffer = NULL; ANativeWindow::query = query; ANativeWindow::perform = perform; ANativeWindow::cancelBuffer = 0; #ifdef OMAP_ENHANCEMENT LOGE("%d buffers flip-chain implementation enabled\n", mNumBuffers); #endif }
FramebufferNativeWindow::FramebufferNativeWindow() : BASE(), fbDev(0), grDev(0), mUpdateOnDemand(false) { hw_module_t const* module; if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { int stride; int err; err = framebuffer_open(module, &fbDev); LOGE_IF(err, "couldn't open framebuffer HAL (%s)", strerror(-err)); err = gralloc_open(module, &grDev); LOGE_IF(err, "couldn't open gralloc HAL (%s)", strerror(-err)); // bail out if we can't initialize the modules if (!fbDev || !grDev) return; mUpdateOnDemand = (fbDev->setUpdateRect != 0); // initialize the buffer FIFO mNumBuffers = 2; mNumFreeBuffers = 2; mBufferHead = mNumBuffers-1; buffers[0] = new NativeBuffer( fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB); buffers[1] = new NativeBuffer( fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB); err = grDev->alloc(grDev, fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB, &buffers[0]->handle, &buffers[0]->stride); LOGE_IF(err, "fb buffer 0 allocation failed w=%d, h=%d, err=%s", fbDev->width, fbDev->height, strerror(-err)); err = grDev->alloc(grDev, fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB, &buffers[1]->handle, &buffers[1]->stride); LOGE_IF(err, "fb buffer 1 allocation failed w=%d, h=%d, err=%s", fbDev->width, fbDev->height, strerror(-err)); const_cast<uint32_t&>(android_native_window_t::flags) = fbDev->flags; const_cast<float&>(android_native_window_t::xdpi) = fbDev->xdpi; const_cast<float&>(android_native_window_t::ydpi) = fbDev->ydpi; const_cast<int&>(android_native_window_t::minSwapInterval) = fbDev->minSwapInterval; const_cast<int&>(android_native_window_t::maxSwapInterval) = fbDev->maxSwapInterval; } else { LOGE("Couldn't get gralloc module"); } android_native_window_t::setSwapInterval = setSwapInterval; android_native_window_t::dequeueBuffer = dequeueBuffer; android_native_window_t::lockBuffer = lockBuffer; android_native_window_t::queueBuffer = queueBuffer; android_native_window_t::query = query; android_native_window_t::perform = perform; //[BEGIN] add by ethaen android_native_window_t::fd = getDeviceFD(); //END //[END] // [BEGIN] skyviia modify: fix lock display issue if framework reboot without unlock display. // fix me! #ifdef SV886X // if (ioctl(android_native_window_t::fd, SKYFB_UNLOCK_DISPLAY) == -1) { // LOGE("unlock display failed !\n"); // } else { // LOGI("unlock display OK !\n"); // } #endif // [END] }
FramebufferNativeWindow::FramebufferNativeWindow() : BASE(), fbDev(0), grDev(0), mUpdateOnDemand(false) { hw_module_t const* module; if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { int stride; int err; err = framebuffer_open(module, &fbDev); LOGE_IF(err, "couldn't open framebuffer HAL (%s)", strerror(-err)); err = gralloc_open(module, &grDev); LOGE_IF(err, "couldn't open gralloc HAL (%s)", strerror(-err)); // bail out if we can't initialize the modules if (!fbDev || !grDev) { if (grDev) { gralloc_close(grDev); grDev = 0; } if (fbDev) { framebuffer_close(fbDev); fbDev = 0; } return; } mUpdateOnDemand = (fbDev->setUpdateRect != 0); // initialize the buffer FIFO mNumBuffers = fbDev->numFramebuffers; mNumFreeBuffers = mNumBuffers; mBufferHead = 0; LOGD("mNumBuffers = %d", mNumBuffers); for(int i = 0; i < mNumBuffers; i++) { buffers[i] = new NativeBuffer( fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB); err = grDev->alloc(grDev, fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB, &buffers[i]->handle, &buffers[i]->stride); LOGE_IF(err, "fb buffer %d allocation failed w=%d, h=%d, err=%s", i, fbDev->width, fbDev->height, strerror(-err)); } const_cast<uint32_t&>(ANativeWindow::flags) = fbDev->flags; const_cast<float&>(ANativeWindow::xdpi) = fbDev->xdpi; const_cast<float&>(ANativeWindow::ydpi) = fbDev->ydpi; const_cast<int&>(ANativeWindow::minSwapInterval) = fbDev->minSwapInterval; const_cast<int&>(ANativeWindow::maxSwapInterval) = fbDev->maxSwapInterval; } else { LOGE("Couldn't get gralloc module"); } ANativeWindow::setSwapInterval = setSwapInterval; ANativeWindow::dequeueBuffer = dequeueBuffer; ANativeWindow::lockBuffer = lockBuffer; ANativeWindow::queueBuffer = queueBuffer; ANativeWindow::cancelBuffer = NULL; ANativeWindow::query = query; ANativeWindow::perform = perform; }