示例#1
0
文件: gralloc.c 项目: Tofee/libhybris
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)
	{
		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;
}
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;
}
示例#4
0
GstGralloc *
gst_gralloc_new ()
{
  hw_module_t *hwmod = NULL;
  gralloc_module_t *gralloc_module = NULL;
  alloc_device_t *alloc_device = NULL;
  GstGralloc *gralloc = NULL;

  int err =
      hw_get_module (GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **) &hwmod);

  if (err != 0) {
    g_warning ("Failed to load gralloc");
    goto out;
  }

  gralloc_module = (gralloc_module_t *) hwmod;
  err = gralloc_open ((const hw_module_t *) gralloc_module, &alloc_device);
  if (err != 0) {
    g_warning ("Failed to open gralloc");
    goto out;
  }

  gralloc = (GstGralloc *) gst_mini_object_new (GST_TYPE_GRALLOC);
  gralloc->gralloc = gralloc_module;
  gralloc->allocator = alloc_device;

out:
  return gralloc;
}
示例#5
0
static void initAllocDev()
{
	if(allocDev)
		return;
	if(!libhardware_dl())
	{
		LOG(LOG_ERROR,"Incompatible libhardware.so");
		return;
	}
	if(hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (hw_module_t const**)&grallocMod) != 0)
	{
		LOG(LOG_ERROR,"Can't load gralloc module");
		return;
	}
	gralloc_open((const hw_module_t*)grallocMod, &allocDev);
	if(!allocDev)
	{
		LOG(LOG_ERROR,"Can't load allocator device");
		return;
	}
	if(!allocDev->alloc || !allocDev->free)
	{
		LOG(LOG_ERROR,"Missing alloc/free functions");
		if(allocDev->common.close)
			gralloc_close(allocDev);
		else
			LOG(LOG_WARNING,"Missing device close function");
		allocDev = {};
		return;
	}
	LOG(LOG_MINIMAL,"alloc device:%p", allocDev);
}
示例#6
0
extern "C" void waylandws_init_module(struct ws_egl_interface *egl_iface)
{
	int err;
	hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **) &gralloc);
	err = gralloc_open((const hw_module_t *) gralloc, &alloc);
	TRACE("++ %lu wayland: got gralloc %p err:%s", pthread_self(), gralloc, strerror(-err));
	eglplatformcommon_init(egl_iface, gralloc, alloc);
}
示例#7
0
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;
}
示例#8
0
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; 
}
int fb_device_open(hw_module_t const *module, const char *name,
		   hw_device_t **device)
{
	alloc_device_t *gralloc_device;
	int err;

	err = gralloc_open(module, &gralloc_device);
	if (err < 0)
		return err;

	/* Initialize our state here */
	fb_context_t *dev = (fb_context_t *)malloc(sizeof *dev);
	memset(dev, 0, sizeof *dev);

	/* Initialize the procs */
	dev->device.common.tag = HARDWARE_DEVICE_TAG;
	dev->device.common.version = 0;
	dev->device.common.module = const_cast<hw_module_t *>(module);
	dev->device.common.close = fb_close;
	dev->device.setSwapInterval = fb_setSwapInterval;
	dev->device.post = fb_post;
	dev->device.setUpdateRect = 0;

	private_module_t *m = (private_module_t*)module;
	err = fb_map(m);
	if (err < 0)
		return err;

	const_cast<uint32_t&>(dev->device.flags) = 0;
	const_cast<uint32_t&>(dev->device.width) = m->mode->hdisplay;
	const_cast<uint32_t&>(dev->device.height) = m->mode->vdisplay;
	const_cast<int&>(dev->device.stride) = m->stride;
	const_cast<int&>(dev->device.format) = HAL_PIXEL_FORMAT_RGB_565;
	const_cast<float&>(dev->device.xdpi) = m->xdpi;
	const_cast<float&>(dev->device.ydpi) = m->ydpi;
	const_cast<float&>(dev->device.fps) = m->fps;
	const_cast<int&>(dev->device.minSwapInterval) = 1;
	const_cast<int&>(dev->device.maxSwapInterval) = 1;

	*device = &dev->device.common;

	return 0;
}
示例#10
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(uint32_t idx)
    : 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;
        const size_t SIZE = 16;
        char fbname[SIZE];
        snprintf(fbname, SIZE, "fb%u", idx);

        err = framebuffer_open_by_name(module, &fbDev, fbname);
        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 = NUM_FRAME_BUFFERS;
        mNumFreeBuffers = NUM_FRAME_BUFFERS;
        mBufferHead = mNumBuffers-1;

        for(i = 0; i < NUM_FRAME_BUFFERS; i++){
            buffers[i] = new NativeBuffer(
                    fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB << idx);
        }

        for(i = 0; i < NUM_FRAME_BUFFERS; i++){
            err = grDev->alloc(grDev,
                    fbDev->width, fbDev->height, fbDev->format,
                    GRALLOC_USAGE_HW_FB << idx, &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;
            }
       }

        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::query = query;
    ANativeWindow::perform = perform;

    LOGE("%d buffers flip-chain implementation enabled\n", mNumBuffers);
}
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]

}
示例#14
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;
        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;
}
示例#15
0
文件: gfx_display.c 项目: aosp/dvp
bool_e gfx_display_allocate(gfx_display_t *gfxd, uint32_t numBuf, uint32_t width, uint32_t height, fourcc_t color)
{
    bool_e allocated = false_e;
    if (gfxd)
    {
        int ret = 0;
        ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const struct hw_module_t **)&gfxd->module);
        DVP_PRINT(DVP_ZONE_VIDEO, "hw_get_module(%s,...) returned %d\n", GRALLOC_HARDWARE_MODULE_ID, ret);
        if (ret < 0)
        {
            DVP_PRINT(DVP_ZONE_VIDEO, "Failed to open Gralloc HW\n");
            return false_e;
        }
        DVP_PRINT(DVP_ZONE_VIDEO, "hw_module_t *%p by %s\n", gfxd->module, gfxd->module->base.common.author);

        ret = gralloc_open((const struct hw_module_t *)gfxd->module, &gfxd->allocator);
        if (ret == 0)
        {
            DVP_PRINT(DVP_ZONE_VIDEO, "gralloc_open() passed!\n");
            gfxd->numBuffers = numBuf;
            gfxd->handles = (IMG_native_handle_t **)calloc(numBuf, sizeof(IMG_native_handle_t *));
            gfxd->images = (image_t **)calloc(numBuf, sizeof(image_t*));
            if (gfxd->handles && gfxd->images)
            {
                uint32_t i = 0;
                int format = 0;
                for (i = 0; i < dimof(colors); i++)
                {
                    if (color == colors[i].color)
                        format = colors[i].format;
                }
                if (format > 0)
                {
                    DVP_PRINT(DVP_ZONE_VIDEO, "Using format %d (0x%x) which is FOURCC 0x%x\n", format, format, color);
                    gfxd->color = color;
                    gfxd->width = width;
                    gfxd->height = height;
                    for (i = 0; i < numBuf; i++)
                    {
                        int usage = GRALLOC_USAGE_HW_TEXTURE |
                                    GRALLOC_USAGE_HW_RENDER |
                                    GRALLOC_USAGE_SW_READ_RARELY | // Non-cached ?
                                    GRALLOC_USAGE_SW_WRITE_NEVER;
                        const struct native_handle_t *handle = NULL;
                        DVP_PRINT(DVP_ZONE_VIDEO, "Asking for %ux%u fmt:%d usage:%d\n", width, height, format, usage);
                        ret = gfxd->allocator->alloc(gfxd->allocator, width, height, format, usage, (buffer_handle_t *)&handle, &gfxd->stride);
                        if (ret == 0)
                        {
                            gfxd->handles[i] = (IMG_native_handle_t *)handle;
                            DVP_PRINT(DVP_ZONE_VIDEO,
                                "Allocated GRALLOC buffer handle version:%d numFD=%d fd[0]=%d fd[1]=%d %ux%u fmt=%d bpp=%u stride=%d\n",
                                gfxd->handles[i]->base.version,
                                gfxd->handles[i]->base.numFds,
                                gfxd->handles[i]->fd[0],
                                gfxd->handles[i]->fd[1],
                                gfxd->handles[i]->iWidth,
                                gfxd->handles[i]->iHeight,
                                gfxd->handles[i]->iFormat,
                                gfxd->handles[i]->uiBpp,
                                gfxd->stride);
                            allocated = true_e;
                        }
                        else
                            allocated = false_e;
                    }
                }
                else
                {
                    DVP_PRINT(DVP_ZONE_VIDEO, "No compatible format found!\n");
                }

                if (allocated)
                {
                    bitfield_init(&gfxd->used, numBuf);
                    gfxd->returnq = queue_create(numBuf, sizeof(void *));
                }
            }
        }
        else
        {
            DVP_PRINT(DVP_ZONE_VIDEO, "Failed to open Gralloc device!\n");
        }
    }
    return allocated;
}