int gralloc_unregister_buffer(gralloc_module_t const* module,
        buffer_handle_t handle)
{
    if (private_handle_t::validate(handle) < 0)
        return -EINVAL;

    /*
     * If the buffer has been mapped during a lock operation, it's time
     * to un-map it. It's an error to be here with a locked buffer.
     * NOTE: the framebuffer is handled differently and is never unmapped.
     */

    private_handle_t* hnd = (private_handle_t*)handle;
    
    ALOGE_IF(hnd->lockState & private_handle_t::LOCK_STATE_READ_MASK,
            "[unregister] handle %p still locked (state=%08x)",
            hnd, hnd->lockState);

    // never unmap buffers that were created in this process
    if (hnd->pid != getpid()) {
        if (hnd->lockState & private_handle_t::LOCK_STATE_MAPPED) {
            gralloc_unmap(module, handle);
        }
        hnd->base = 0;
        hnd->lockState  = 0;
        hnd->writeOwner = 0;
    }
    return 0;
}
Exemple #2
0
int PedometerSensor::FindDataFd() {
	int fd = -1;
	int num = -1;
	char buf[64]={0};
	const char *devnum_dir = NULL;
	char buf_s[64] = {0};
    int len;

	devnum_dir = "/sys/class/misc/m_pdr_misc/pdrdevnum";
	
	fd = open(devnum_dir, O_RDONLY);
	if (fd >= 0)
	{
        len = read(fd, buf, sizeof(buf)-1);
        if (len <= 0)
        {
            ALOGD("read devnum err buf(%s)", buf);
            return -1;
        }
        else
        {
            buf[len] = '\0';
            sscanf(buf, "%d\n", &num);
            ALOGE("len = %d, buf = %s",len, buf);
        }
		close(fd);
	}else{
		return -1;
	}
	sprintf(buf_s, "/dev/input/event%d", num);
	fd = open(buf_s, O_RDONLY);
    ALOGE_IF(fd<0, "couldn't find input device");
	return fd;
}
status_t StreamOutHalHidl::write(const void *buffer, size_t bytes, size_t *written) {
    if (mStream == 0) return NO_INIT;
    *written = 0;

    if (bytes == 0 && !mDataMQ) {
        // Can't determine the size for the MQ buffer. Wait for a non-empty write request.
        ALOGW_IF(mCallback.unsafe_get(), "First call to async write with 0 bytes");
        return OK;
    }

    status_t status;
    if (!mDataMQ && (status = prepareForWriting(bytes)) != OK) {
        return status;
    }

    return callWriterThread(
            WriteCommand::WRITE, "write", static_cast<const uint8_t*>(buffer), bytes,
            [&] (const WriteStatus& writeStatus) {
                *written = writeStatus.reply.written;
                // Diagnostics of the cause of b/35813113.
                ALOGE_IF(*written > bytes,
                        "hal reports more bytes written than asked for: %lld > %lld",
                        (long long)*written, (long long)bytes);
            });
}
sensors_poll_context_t::sensors_poll_context_t()
{
    mSensors[hwmsen] = new Hwmsen();
    mPollFds[hwmsen].fd = mSensors[hwmsen]->getFd();
    mPollFds[hwmsen].events = POLLIN;
    mPollFds[hwmsen].revents = 0;

	mSensors[accel] = new AccelerationSensor();
    mPollFds[accel].fd = mSensors[accel]->getFd();
    mPollFds[accel].events = POLLIN;
    mPollFds[accel].revents = 0;

	mSensors[magnetic] = new MagneticSensor();
    mPollFds[magnetic].fd = mSensors[magnetic]->getFd();
    mPollFds[magnetic].events = POLLIN;
    mPollFds[magnetic].revents = 0;

    int wakeFds[2];
    int result = pipe(wakeFds);
    ALOGE_IF(result<0, "error creating wake pipe (%s)", strerror(errno));
    fcntl(wakeFds[0], F_SETFL, O_NONBLOCK);
    fcntl(wakeFds[1], F_SETFL, O_NONBLOCK);
    mWritePipeFd = wakeFds[1];

    mPollFds[wake].fd = wakeFds[0];
    mPollFds[wake].events = POLLIN;
    mPollFds[wake].revents = 0;
}
int SensorBase::open_fifo_device(){
	if (fifo_fd < 0 && fifo_name) {
        fifo_fd = open(fifo_name, O_RDONLY);
        ALOGE_IF(fifo_fd < 0, "Couldn't  open %s (%s)", fifo_name, strerror(errno));
    }
	return 0;
}
Exemple #6
0
void TimeInterpolator::seek(int64_t media_time)
{
    Mutex::Autolock mlock(m_mutex);
    ALOGV("TimeInterpolator::seek(media_time=%lld)", media_time);

    if (m_state == STOPPED || m_state == PAUSED) {
        m_pos0 = media_time;
        m_read = media_time;
        m_queued = 0;
        m_t0 = get_system_usecs();
        m_Tf = 0;
        m_last = media_time;
        m_now_last = 0;
    } else {
        ALOGE_IF(m_state != ROLLING, "TimeInterpolator logic error: "
                "state is not rolling in seek()");
        m_read = media_time;
        m_pos0 = m_read - m_latency;
        m_queued = 0;
        m_t0 = get_system_usecs();
        m_Tf = 1.0;
        m_last = m_pos0;
        m_now_last = 0;
    }
}
int sensors_poll_context_t::activate(int handle, int enabled) 
{
	ALOGD( "activate handle =%d, enable = %d",handle, enabled );
	int err=0;
	
	int index = handleToDriver(handle);

	//
	if(ID_ORIENTATION == handle)
	{
	     //ALOGD( "fwq1111" );
		((AccelerationSensor*)(mSensors[accel]))->enableNoHALDataAcc(enabled);
		((Hwmsen*)(mSensors[hwmsen]))->enableNoHALDataAcc(enabled);
	}
	
	if(NULL != mSensors[index] && index >0 )
	{
	   ALOGD( "use new sensor index=%d, mSensors[index](%x)", index, mSensors[index]);
	   err =  mSensors[index]->enable(handle, enabled);
	}
	
	if(err || index<0 )
	{
  		ALOGD("use old sensor err(%d),index(%d) go to old hwmsen\n",err,index);
		// notify to hwmsen sensor to support old architecture
		err =  mSensors[hwmsen]->enable(handle, enabled);
	}
	
    if (enabled && !err) {
        const char wakeMessage(WAKE_MESSAGE);
        int result = write(mWritePipeFd, &wakeMessage, 1);
        ALOGE_IF(result<0, "error sending wake message (%s)", strerror(errno));
    }
    return err;
}
Exemple #8
0
int Kxtf9Sensor::setDelay(int32_t handle, int64_t ns)
{
    int err = 0;

    if (mEnabled) {
        if (ns < 0)
            return -EINVAL;

        unsigned long delay = ns / 1000000;

        // ok we need to set our enabled state
        int fd = open(KXTF9_DELAY_FILE, O_WRONLY);
        if(fd >= 0) {
            char buffer[20];
            int bytes = sprintf(buffer, "%d\n", delay);
            err = write(fd, buffer, bytes);
            err = err < 0 ? -errno : 0;
        } else {
            err = -errno;
        }

        ALOGE_IF(err < 0, "Error setting delay of kxtf9 accelerometer (%s)", strerror(-err));
    }

    return err;
}
static void teardownWfd(hwc_context_t* ctx) {
    // Teardown WFD display
    ALOGD_IF(UEVENT_DEBUG,"Received HDMI connection request when WFD is "
            "active");
    {
        Locker::Autolock _l(ctx->mDrawLock);
        clear(ctx, HWC_DISPLAY_VIRTUAL);
        ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
        ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
    }

    ctx->mVirtualDisplay->teardown();

    /* Need to send hotplug only when connected WFD in proprietary path */
    if(ctx->mVirtualonExtActive) {
        ALOGE_IF(UEVENT_DEBUG,"%s: Sending EXTERNAL OFFLINE"
                "hotplug event for wfd display", __FUNCTION__);
        ctx->proc->hotplug(ctx->proc, HWC_DISPLAY_EXTERNAL,
                EXTERNAL_OFFLINE);
        {
            Locker::Autolock _l(ctx->mDrawLock);
            ctx->mVirtualonExtActive = false;
        }
    }

    ctx->mWfdSyncLock.lock();
    ALOGD_IF(HWC_WFDDISPSYNC_LOG,
            "%s: Waiting for wfd-teardown to be signalled",__FUNCTION__);
    ctx->mWfdSyncLock.wait();
    ALOGD_IF(HWC_WFDDISPSYNC_LOG,
            "%s: Teardown signalled. Completed waiting in uevent thread",
            __FUNCTION__);
    ctx->mWfdSyncLock.unlock();
}
sensors_poll_context_t::sensors_poll_context_t()
{
    mSensors[accel_kxtj9] = new KionixSensor();
    mPollFds[accel_kxtj9].fd = mSensors[accel_kxtj9]->getFd();
    mPollFds[accel_kxtj9].events = POLLIN;
    mPollFds[accel_kxtj9].revents = 0;
    
    mSensors[light_cm3212] = new LightSensor();
    mPollFds[light_cm3212].fd = mSensors[light_cm3212]->getFd();
    mPollFds[light_cm3212].events = POLLIN;
    mPollFds[light_cm3212].revents = 0;

    mSensors[compass_ami30x] = new AmiSensor();
    mPollFds[compass_ami30x].fd = mSensors[compass_ami30x]->getFd();
    mPollFds[compass_ami30x].events = POLLIN;
    mPollFds[compass_ami30x].revents = 0;
	
    mSensors[accel_dmard06] = new Dmard06Sensor();
    mPollFds[accel_dmard06].fd = mSensors[accel_dmard06]->getFd();
    mPollFds[accel_dmard06].events = POLLIN;
    mPollFds[accel_dmard06].revents = 0;
    int wakeFds[2];
    int result = pipe(wakeFds);
    ALOGE_IF(result<0, "error creating wake pipe (%s)", strerror(errno));
    fcntl(wakeFds[0], F_SETFL, O_NONBLOCK);
    fcntl(wakeFds[1], F_SETFL, O_NONBLOCK);
    mWritePipeFd = wakeFds[1];

    mPollFds[wake].fd = wakeFds[0];
    mPollFds[wake].events = POLLIN;
    mPollFds[wake].revents = 0;
}
Exemple #11
0
int Kxtf9Sensor::enable(int32_t handle, int en)
{
    int err = 0;

    int newState = en ? 1 : 0;

    // don't set enable state if it's already valid
    if(mEnabled == newState) {
        return err;
    }

    // ok we need to set our enabled state
    int fd = open(KXTF9_ENABLE_FILE, O_WRONLY);
    if(fd >= 0) {
        char buffer[20];
        int bytes = sprintf(buffer, "%d\n", newState);
        err = write(fd, buffer, bytes);
        err = err < 0 ? -errno : 0;
    } else {
        err = -errno;
    }

    ALOGE_IF(err < 0, "Error setting enable of kxtf9 accelerometer (%s)", strerror(-err));

    if (!err) {
        mEnabled = newState;
        setDelay(0, 100000000); // 100ms by default for faster re-orienting
    }

    return err;
}
int gralloc_free_pmem(alloc_device_t* dev,
        struct hwmem_gralloc_buf_handle_t* hnd)
{
    if (hnd->flags & PRIV_FLAGS_FRAMEBUFFER) {
        // free this buffer
        struct hwmem_gralloc_module_t* m = (struct hwmem_gralloc_module_t*)
                dev->common.module;
        const size_t bufferSize = m->finfo.line_length * m->info.yres;
        int index = (hnd->base_addr - m->framebuffer->base_addr) / bufferSize;
        m->bufferMask &= ~(1<<index);
    } else {
#if HAVE_ANDROID_OS
        if (hnd->flags & PRIV_FLAGS_USES_PMEM) {
            if (hnd->fd >= 0) {
                struct pmem_region sub = { hnd->offset, hnd->size };
                int err = ioctl(hnd->fd, PMEM_UNMAP, &sub);
                ALOGE_IF(err<0, "PMEM_UNMAP failed (%s), "
                        "fd=%d, sub.offset=%i, sub.size=%i",
                        strerror(errno), hnd->fd, hnd->offset, hnd->size);
            }
        }
#endif // HAVE_ANDROID_OS
        terminateBuffer(NULL, hnd); /* NULL is ok here as the parameter is not used by terminateBuffer */
    }

    close(hnd->fd);
    free(hnd);
    return 0;
}
static int terminateBuffer(gralloc_module_t const* module,
        struct hwmem_gralloc_buf_handle_t* hnd)
{
    /*
     * If the buffer has been mapped during a lock operation, it's time
     * to un-map it. It's an error to be here with a locked buffer.
     */

    ALOGE_IF(hnd->lockState & LOCK_STATE_READ_MASK,
            "[terminate] handle %p still locked (state=%08x)",
            hnd, hnd->lockState);

    if (hnd->lockState & LOCK_STATE_MAPPED) {
        // this buffer was mapped, unmap it now
        if ((hnd->flags & PRIV_FLAGS_USES_PMEM) &&
            (hnd->pid == getpid())) {
            // ... unless it's a "master" pmem buffer, that is a buffer
            // mapped in the process it's been allocated.
            // (see gralloc_alloc_buffer())
        } else {
            gralloc_unmap(module, hnd);
        }
    }

    return 0;
}
int terminateBuffer(gralloc_module_t const* module,
        private_handle_t* hnd)
{
    /*
     * If the buffer has been mapped during a lock operation, it's time
     * to un-map it. It's an error to be here with a locked buffer.
     */

    ALOGE_IF(hnd->lockState & private_handle_t::LOCK_STATE_READ_MASK,
            "[terminate] handle %p still locked (state=%08x)",
            hnd, hnd->lockState);

    if (hnd->lockState & private_handle_t::LOCK_STATE_MAPPED) {
        // this buffer was mapped, unmap it now
        if (hnd->flags & (private_handle_t::PRIV_FLAGS_USES_PMEM |
                          private_handle_t::PRIV_FLAGS_USES_PMEM_ADSP |
                          private_handle_t::PRIV_FLAGS_USES_ASHMEM)) {
            if (hnd->pid != getpid()) {
                // ... unless it's a "master" pmem buffer, that is a buffer
                // mapped in the process it's been allocated.
                // (see gralloc_alloc_buffer())
                gralloc_unmap(module, hnd);
            }
        } else {
            LOGE("terminateBuffer: unmapping a non pmem/ashmem buffer flags = 0x%x", hnd->flags);
            gralloc_unmap(module, hnd);
        }
    }

    return 0;
}
GraphicBufferMapper::GraphicBufferMapper()
    : mAllocMod(0)
{
    hw_module_t const* module;
    int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
    ALOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID);
    if (err == 0) {
        mAllocMod = (gralloc_module_t const *)module;
    }

    // [MTK] {{{
    // 20120918: gralloc extra device for internal purpose
    mExtraDev = NULL;
    if (err == 0) {
        gralloc_extra_open(module, &mExtraDev);
    }

    char value[PROPERTY_VALUE_MAX];
    property_get("debug.gbuf.callstack", value, "0");
    mIsDumpCallStack = atoi(value);
    if (true == mIsDumpCallStack) {
        XLOGI("!!! dump GraphicBufferMapper callstack for pid:%d !!!", getpid());
    }
    // [MTK] }}}
}
sensors_poll_context_t::sensors_poll_context_t()
{
    mSensors[lsm303dlh_acc] = new Lsm303dlhGSensor();
    mPollFds[lsm303dlh_acc].fd = mSensors[lsm303dlh_acc]->getFd();
    mPollFds[lsm303dlh_acc].events = POLLIN;
    mPollFds[lsm303dlh_acc].revents = 0;

    mSensors[lsm303dlh_mag] = new Lsm303dlhMagSensor();
    mPollFds[lsm303dlh_mag].fd = mSensors[lsm303dlh_mag]->getFd();
    mPollFds[lsm303dlh_mag].events = POLLIN;
    mPollFds[lsm303dlh_mag].revents = 0;

    mSensors[isl29023_als] = new LightSensor();
    mPollFds[isl29023_als].fd = mSensors[isl29023_als]->getFd();
    mPollFds[isl29023_als].events = POLLIN;
    mPollFds[isl29023_als].revents = 0;

    mSensors[mpu3050] = new MPLSensor();
    mPollFds[mpu3050].fd = mSensors[mpu3050]->getFd();
    mPollFds[mpu3050].events = POLLIN;
    mPollFds[mpu3050].revents = 0;

    int wakeFds[2];
    int result = pipe(wakeFds);
    ALOGE_IF(result<0, "error creating wake pipe (%s)", strerror(errno));
    fcntl(wakeFds[0], F_SETFL, O_NONBLOCK);
    fcntl(wakeFds[1], F_SETFL, O_NONBLOCK);
    mWritePipeFd = wakeFds[1];

    mPollFds[wake].fd = wakeFds[0];
    mPollFds[wake].events = POLLIN;
    mPollFds[wake].revents = 0;
}
bool GenericPipe::init()
{
    ALOGE_IF(DEBUG_OVERLAY, "GenericPipe init");
    mRotDownscaleOpt = false;

    int fbNum = Overlay::getFbForDpy(mDpy);
    if( fbNum < 0 ) {
        ALOGE("%s: Invalid FB for the display: %d",__FUNCTION__, mDpy);
        return false;
    }

    ALOGD_IF(DEBUG_OVERLAY,"%s: mFbNum:%d",__FUNCTION__, fbNum);


    if(!mCtrlData.ctrl.init(fbNum)) {
        ALOGE("GenericPipe failed to init ctrl");
        return false;
    }

    if(!mCtrlData.data.init(fbNum)) {
        ALOGE("GenericPipe failed to init data");
        return false;
    }

    return true;
}
// establish binder interface to MediaPlayerService
/*static*/const sp<IMediaPlayerService>&
IMediaDeathNotifier::getMediaPlayerService()
{
    ALOGV("getMediaPlayerService");
    Mutex::Autolock _l(sServiceLock);
    if (sMediaPlayerService == 0) {
        sp<IServiceManager> sm = defaultServiceManager();
        sp<IBinder> binder;
        do {
            binder = sm->getService(String16("media.player"));
            if (binder != 0) {
                break;
            }
            ALOGW("Media player service not published, waiting...");
            usleep(500000); // 0.5 s
        } while (true);

        if (sDeathNotifier == NULL) {
        sDeathNotifier = new DeathNotifier();
    }
    binder->linkToDeath(sDeathNotifier);
    sMediaPlayerService = interface_cast<IMediaPlayerService>(binder);
    }
    ALOGE_IF(sMediaPlayerService == 0, "no media player service!?");
    return sMediaPlayerService;
}
void BootAnimation::onFirstRef() {
    status_t err = mSession->linkToComposerDeath(this);
    ALOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err));
    if (err == NO_ERROR) {
        run("BootAnimation", PRIORITY_DISPLAY);
    }
}
int SensorBase::openDevice() {
    if ((mDevFd < 0) && mDevName) {
        mDevFd = open(mDevName, O_RDONLY);
        ALOGE_IF(mDevFd < 0, "Couldn't open %s (%s)", mDevName, strerror(errno));
    }
    return 0;
}
static void teardownWfd(hwc_context_t* ctx) {
    // Teardown WFD display
    ALOGD_IF(UEVENT_DEBUG,"Received HDMI connection request when WFD is "
            "active");
    {
        Locker::Autolock _l(ctx->mDrawLock);
        clear(ctx, HWC_DISPLAY_VIRTUAL);
        ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
        ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
    }

    ctx->mVirtualDisplay->teardown();

    /* Need to send hotplug only when connected WFD in proprietary path */
    if(ctx->mVirtualonExtActive) {
        ALOGE_IF(UEVENT_DEBUG,"%s: Sending EXTERNAL OFFLINE"
                "hotplug event for wfd display", __FUNCTION__);
        ctx->proc->hotplug(ctx->proc, HWC_DISPLAY_EXTERNAL,
                EXTERNAL_OFFLINE);
        {
            Locker::Autolock _l(ctx->mDrawLock);
            ctx->mVirtualonExtActive = false;
        }
    }
    /* Wait for few frames for SF to tear down the WFD session. */
    usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
            * 2 / 1000);
}
sensors_poll_context_t::sensors_poll_context_t()
{
	int number;
	int i;
	const struct sensor_t *slist;
	const struct SensorContext *context;
	NativeSensorManager& sm(NativeSensorManager::getInstance());

	number = sm.getSensorList(&slist);

	/* use the dynamic sensor list */
	for (i = 0; i < number; i++) {
		context = sm.getInfoByHandle(slist[i].handle);

		mPollFds[i].fd = (context == NULL) ? -1 : context->data_fd;
		mPollFds[i].events = POLLIN;
		mPollFds[i].revents = 0;
	}

	ALOGI("The avaliable sensor handle number is %d",i);
	int wakeFds[2];
	int result = pipe(wakeFds);
	ALOGE_IF(result<0, "error creating wake pipe (%s)", strerror(errno));
	fcntl(wakeFds[0], F_SETFL, O_NONBLOCK);
	fcntl(wakeFds[1], F_SETFL, O_NONBLOCK);
	mWritePipeFd = wakeFds[1];

	mPollFds[number].fd = wakeFds[0];
	mPollFds[number].events = POLLIN;
	mPollFds[number].revents = 0;
}
void MdpRot::setTransform(const utils::eTransform& rot)
{
    int r = utils::getMdpOrient(rot);
    setRotations(r);
    mOrientation = static_cast<utils::eTransform>(r);
    ALOGE_IF(DEBUG_OVERLAY, "%s: r=%d", __FUNCTION__, r);
}
bool egl_display_t::HibernationMachine::incWakeCount(WakeRefStrength strength) {
    Mutex::Autolock _l(mLock);
    ALOGE_IF(mWakeCount < 0 || mWakeCount == INT32_MAX,
             "Invalid WakeCount (%d) on enter\n", mWakeCount);

    mWakeCount++;
    if (strength == STRONG)
        mAttemptHibernation = false;

    if (CC_UNLIKELY(mHibernating)) {
        ALOGV("Awakening\n");
        egl_connection_t* const cnx = &gEGLImpl;

        // These conditions should be guaranteed before entering hibernation;
        // we don't want to get into a state where we can't wake up.
        ALOGD_IF(!mDpyValid || !cnx->egl.eglAwakenProcessIMG,
                 "Invalid hibernation state, unable to awaken\n");

        if (!cnx->egl.eglAwakenProcessIMG()) {
            ALOGE("Failed to awaken EGL implementation\n");
            return false;
        }
        mHibernating = false;
    }
    return true;
}
Exemple #25
0
int SensorBase::open_device() {
    if (dev_fd<0 && dev_name) {
        dev_fd = open(dev_name, O_RDONLY);
        ALOGE_IF(dev_fd<0, "Couldn't open %s (%s)", dev_name, strerror(errno));
    }
    return 0;
}
// establish binder interface to AudioFlinger service
const sp<IAudioFlinger>& AudioSystem::get_audio_flinger()
{
    Mutex::Autolock _l(gLock);
    if (gAudioFlinger == 0) {
        sp<IServiceManager> sm = defaultServiceManager();
        sp<IBinder> binder;
        do {
            binder = sm->getService(String16("media.audio_flinger"));
            if (binder != 0)
                break;
            ALOGW("AudioFlinger not published, waiting...");
            usleep(500000); // 0.5 s
        } while (true);
        if (gAudioFlingerClient == NULL) {
            gAudioFlingerClient = new AudioFlingerClient();
        } else {
            if (gAudioErrorCallback) {
                gAudioErrorCallback(NO_ERROR);
            }
        }
        binder->linkToDeath(gAudioFlingerClient);
        gAudioFlinger = interface_cast<IAudioFlinger>(binder);
        gAudioFlinger->registerClient(gAudioFlingerClient);
    }
    ALOGE_IF(gAudioFlinger==0, "no AudioFlinger!?");

    return gAudioFlinger;
}
void BpMemoryHeap::assertReallyMapped() const
{
    if (mHeapId == -1) {

        // remote call without mLock held, worse case scenario, we end up
        // calling transact() from multiple threads, but that's not a problem,
        // only mmap below must be in the critical section.

        Parcel data, reply;
        data.writeInterfaceToken(IMemoryHeap::getInterfaceDescriptor());
        status_t err = remote()->transact(HEAP_ID, data, &reply);
        int parcel_fd = reply.readFileDescriptor();
        ssize_t size = reply.readInt32();
        uint32_t flags = reply.readInt32();
        uint32_t offset = reply.readInt32();

        ALOGE_IF(err, "binder=%p transaction failed fd=%d, size=%zd, err=%d (%s)",
                IInterface::asBinder(this).get(),
                parcel_fd, size, err, strerror(-err));

        Mutex::Autolock _l(mLock);
        if (mHeapId == -1) {
            int fd = dup( parcel_fd );
            ALOGE_IF(fd==-1, "cannot dup fd=%d, size=%zd, err=%d (%s)",
                    parcel_fd, size, err, strerror(errno));

            int access = PROT_READ;
            if (!(flags & READ_ONLY)) {
                access |= PROT_WRITE;
            }

            mRealHeap = true;
            mBase = mmap(0, size, access, MAP_SHARED, fd, offset);
            if (mBase == MAP_FAILED) {
                ALOGE("cannot map BpMemoryHeap (binder=%p), size=%zd, fd=%d (%s)",
                        IInterface::asBinder(this).get(), size, fd, strerror(errno));
                close(fd);
            } else {
                mSize = size;
                mFlags = flags;
                mOffset = offset;
                android_atomic_write(fd, &mHeapId);
            }
        }
    }
}
Exemple #28
0
RenderEngine::BindImageAsFramebuffer::BindImageAsFramebuffer(
    RenderEngine& engine, EGLImageKHR image) : mEngine(engine)
{
    mEngine.bindImageAsFramebuffer(image, &mTexName, &mFbName, &mStatus);

    ALOGE_IF(mStatus != GL_FRAMEBUFFER_COMPLETE_OES,
             "glCheckFramebufferStatusOES error %d", mStatus);
}
int MPLSensor::readEvents(sensors_event_t* data, int count)
{
    //VFUNC_LOG;
    int i;
    bool irq_set[5] = { false, false, false, false, false };
    inv_error_t rv;
    if (count < 1)
        return -EINVAL;
    int numEventReceived = 0;

    clearIrqData(irq_set);

    pthread_mutex_lock(&mMplMutex);
    if (mDmpStarted) {
        //ALOGV_IF(EXTRA_VERBOSE, "Update Data");
        rv = inv_update_data();
        ALOGE_IF(rv != INV_SUCCESS, "inv_update_data error (code %d)", (int) rv);
    }

    else {
        //probably just one extra read after shutting down
        ALOGV_IF(EXTRA_VERBOSE,
                "MPLSensor::readEvents called, but there's nothing to do.");
    }

    pthread_mutex_unlock(&mMplMutex);

    if (!mNewData) {
        ALOGV_IF(EXTRA_VERBOSE, "no new data");
        return 0;
    }
    mNewData = 0;
    
    /* google timestamp */
    pthread_mutex_lock(&mMplMutex);
    for (int i = 0; i < numSensors; i++) {
        if (mEnabled & (1 << i)) {
            CALL_MEMBER_FN(this,mHandlers[i])(mPendingEvents + i,
                                              &mPendingMask, i);
	    mPendingEvents[i].timestamp = irq_timestamp;
        }
    }

    for (int j = 0; count && mPendingMask && j < numSensors; j++) {
        if (mPendingMask & (1 << j)) {
            mPendingMask &= ~(1 << j);
            if (mEnabled & (1 << j)) {
                *data++ = mPendingEvents[j];
                count--;
                numEventReceived++;
            }
        }

    }

    pthread_mutex_unlock(&mMplMutex);
    return numEventReceived;
}
Exemple #30
0
void Mapper::freeBuffer(buffer_handle_t bufferHandle) const
{
    auto buffer = const_cast<native_handle_t*>(bufferHandle);
    auto ret = mMapper->freeBuffer(buffer);

    auto error = (ret.isOk()) ? static_cast<Error>(ret) : kTransactionError;
    ALOGE_IF(error != Error::NONE, "freeBuffer(%p) failed with %d",
            buffer, error);
}