Beispiel #1
0
bool BootAnimation::android() {
    initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png");
    initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png");

    // clear screen
    glDisable(GL_DITHER);
    glDisable(GL_SCISSOR_TEST);
    glClear(GL_COLOR_BUFFER_BIT);
    eglSwapBuffers(mDisplay, mSurface);

    const GLint xc = (mWidth  - mAndroid[0].w) / 2;
    const GLint yc = (mHeight - mAndroid[0].h) / 2;
    const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h);

    // draw and update only what we need
    mNativeWindowSurface->setSwapRectangle(updateRect.left,
            updateRect.top, updateRect.width(), updateRect.height());

    glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(),
            updateRect.height());

    // Blend state
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    const nsecs_t startTime = systemTime();
    do {
        nsecs_t now = systemTime();
        double time = now - startTime;
        float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w;
        GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w;
        GLint x = xc - offset;

        glDisable(GL_SCISSOR_TEST);
        glClear(GL_COLOR_BUFFER_BIT);

        glEnable(GL_SCISSOR_TEST);
        glDisable(GL_BLEND);
        glBindTexture(GL_TEXTURE_2D, mAndroid[1].name);
        glDrawTexiOES(x,                 yc, 0, mAndroid[1].w, mAndroid[1].h);
        glDrawTexiOES(x + mAndroid[1].w, yc, 0, mAndroid[1].w, mAndroid[1].h);

        glEnable(GL_BLEND);
        glBindTexture(GL_TEXTURE_2D, mAndroid[0].name);
        glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h);

        EGLBoolean res = eglSwapBuffers(mDisplay, mSurface);
        if (res == EGL_FALSE)
            break;

        // 12fps: don't animate too fast to preserve CPU
        const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now);
        if (sleepTime > 0)
            usleep(sleepTime); 
    } while (!exitPending());

    glDeleteTextures(1, &mAndroid[0].name);
    glDeleteTextures(1, &mAndroid[1].name);
    return false;
}
status_t SensorEventQueue::enableSensor(int32_t handle, int32_t us) const {
    status_t err = mSensorEventConnection->enableDisable(handle, true);
    if (err == NO_ERROR) {
        mSensorEventConnection->setEventRate(handle, us2ns(us));
    }
    return err;
}
Beispiel #3
0
bool EventHub::getEvent(int32_t* outDeviceId, int32_t* outType,
        int32_t* outScancode, int32_t* outKeycode, uint32_t *outFlags,
        int32_t* outValue, nsecs_t* outWhen)
{
    *outDeviceId = 0;
    *outType = 0;
    *outScancode = 0;
    *outKeycode = 0;
    *outFlags = 0;
    *outValue = 0;
    *outWhen = 0;

    status_t err;

    fd_set readfds;
    int maxFd = -1;
    int cc;
    int i;
    int res;
    int pollres;
    struct input_event iev;

    // Note that we only allow one caller to getEvent(), so don't need
    // to do locking here...  only when adding/removing devices.

    if (!mOpened) {
        mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR;
        mOpened = true;
    }

    while(1) {
#ifdef HAVE_TSLIB
        //Checks if we have to send any more events read by input-raw plugin.
        if(!samp.total_events) {
#endif
            // First, report any devices that had last been added/removed.
            if (mClosingDevices != NULL) {
                device_t* device = mClosingDevices;
                LOGV("Reporting device closed: id=0x%x, name=%s\n",
                     device->id, device->path.string());
                mClosingDevices = device->next;
                *outDeviceId = device->id;
                if (*outDeviceId == mFirstKeyboardId) *outDeviceId = 0;
                *outType = DEVICE_REMOVED;
                delete device;
                return true;
            }
            if (mOpeningDevices != NULL) {
                device_t* device = mOpeningDevices;
                LOGV("Reporting device opened: id=0x%x, name=%s\n",
                     device->id, device->path.string());
                mOpeningDevices = device->next;
                *outDeviceId = device->id;
                if (*outDeviceId == mFirstKeyboardId) *outDeviceId = 0;
                *outType = DEVICE_ADDED;
                return true;
            }

            release_wake_lock(WAKE_LOCK_ID);

            pollres = poll(mFDs, mFDCount, -1);

            acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);

            if (pollres <= 0) {
                if (errno != EINTR) {
                    LOGW("select failed (errno=%d)\n", errno);
                    usleep(100000);
                }
                continue;
            }

            //printf("poll %d, returned %d\n", mFDCount, pollres);

            // mFDs[0] is used for inotify, so process regular events starting at mFDs[1]
            for(i = 1; i < mFDCount; i++) {
                if(mFDs[i].revents) {
                    LOGV("revents for %d = 0x%08x", i, mFDs[i].revents);
                    if(mFDs[i].revents & POLLIN) {
#ifdef HAVE_TSLIB
                        LOGV("Inside EventHub.cpp with mFDs[i].fd=%d \n", mFDs[i].fd);
                        if (mTS != NULL) {
                            if (mFDs[i].fd != mTS->fd ) {
                                LOGV("mFDs[%d].fd = %d and mTS->fd = %d", i, mFDs[i].fd, mTS->fd);
#endif
                                res = read(mFDs[i].fd, &iev, sizeof(iev));
#ifdef HAVE_TSLIB
                            }
                            else{
                                LOGV("mTS->fd = %d", mTS->fd);
                                LOGV("tslib: calling ts_read from eventhub\n");
                                res = ts_read(mTS, &samp, 1);

                                if (res < 0) {
                                    LOGE("[EventHub.cpp:: After Poll] Error in ts_read()\n");
                                }
                                else {
                                    numOfEventsSent = 0;
                                    samp.tsIndex = i;
                                    break;
                                }
                            }
                        }
                        else {
                            LOGE("ERROR in setup of mTS: mTS is NULL!\n");
                        }
#endif
                        if (res == sizeof(iev)
#ifdef HAVE_TSLIB
                            || ((iev.code == 0x1d || iev.code == 0x1e) && res >= 0)
#endif
                        ) {
                        LOGV("%s got: t0=%d, t1=%d, type=%d, code=%d, v=%d",
                             mDevices[i]->path.string(),
                             (int) iev.time.tv_sec, (int) iev.time.tv_usec,
                             iev.type, iev.code, iev.value);
                        *outDeviceId = mDevices[i]->id;
                        if (*outDeviceId == mFirstKeyboardId) *outDeviceId = 0;
                        *outType = iev.type;
                        *outScancode = iev.code;
                        if (iev.type == EV_KEY) {
                            err = mDevices[i]->layoutMap->map(iev.code, outKeycode, outFlags);
                            LOGV("iev.code=%d outKeycode=%d outFlags=0x%08x err=%d\n",
                                iev.code, *outKeycode, *outFlags, err);
                            if (err != 0) {
                                *outKeycode = 0;
                                *outFlags = 0;
                            }
                        } else {
                            *outKeycode = iev.code;
                        }
                        *outValue = iev.value;
                        *outWhen = s2ns(iev.time.tv_sec) + us2ns(iev.time.tv_usec);
                        return true;
                    } else {
                        if (res<0) {
                            LOGW("could not get event (errno=%d)", errno);
                        } else {
                            LOGE("could not get event (wrong size: %d)", res);
                        }
                        continue;
                        }
                    }
                }
            }

        // read_notify() will modify mFDs and mFDCount, so this must be done after
        // processing all other events.
            if(mFDs[0].revents & POLLIN) {
                read_notify(mFDs[0].fd);
            }
#ifdef HAVE_TSLIB
        }

        if(samp.total_events) {
            *outDeviceId = mDevices[samp.tsIndex]->id;
            *outType = samp.ev[numOfEventsSent].type;
            *outScancode = samp.ev[numOfEventsSent].code;
            if (samp.ev[numOfEventsSent].type == EV_KEY) {
                err = mDevices[samp.tsIndex]->layoutMap->map(samp.ev[numOfEventsSent].code, outKeycode, outFlags);
                if (err != 0) {
                    *outKeycode = 0;
                    *outFlags = 0;
                }
            }
            else {
                *outKeycode =  samp.ev[numOfEventsSent].code;
            }
            if(*outType == EV_ABS) {
                if(*outScancode == ABS_X)
                    *outValue = samp.x;
                if(*outScancode == ABS_Y)
                    *outValue = samp.y;
                if(*outScancode == ABS_PRESSURE)
                    *outValue = samp.pressure;
            }
            else {
                *outValue = samp.ev[numOfEventsSent].value;
                *outWhen = s2ns(iev.time.tv_sec) + us2ns(iev.time.tv_usec);
            }
            if(++numOfEventsSent == samp.total_events)
                samp.total_events = 0;
            return true;
        }
#endif
    }
}
Beispiel #4
0
void EvdevDevice::processInput(InputEvent& event, nsecs_t currentTime) {
#if DEBUG_INPUT_EVENTS
    std::string log;
    log.append("---InputEvent for device %s---\n");
    log.append("   when:  %" PRId64 "\n");
    log.append("   type:  %d\n");
    log.append("   code:  %d\n");
    log.append("   value: %d\n");
    ALOGD(log.c_str(), mDeviceNode->getPath().c_str(), event.when, event.type, event.code,
            event.value);
#endif

    if (event.type == EV_MSC) {
        if (event.code == MSC_ANDROID_TIME_SEC) {
            mOverrideSec = event.value;
        } else if (event.code == MSC_ANDROID_TIME_USEC) {
            mOverrideUsec = event.value;
        }
        return;
    }

    if (mOverrideSec || mOverrideUsec) {
        event.when = s2ns(mOverrideSec) + us2ns(mOverrideUsec);
        ALOGV("applied override time %d.%06d", mOverrideSec, mOverrideUsec);

        if (event.type == EV_SYN && event.code == SYN_REPORT) {
            mOverrideSec = 0;
            mOverrideUsec = 0;
        }
    }

    // Bug 7291243: Add a guard in case the kernel generates timestamps
    // that appear to be far into the future because they were generated
    // using the wrong clock source.
    //
    // This can happen because when the input device is initially opened
    // it has a default clock source of CLOCK_REALTIME.  Any input events
    // enqueued right after the device is opened will have timestamps
    // generated using CLOCK_REALTIME.  We later set the clock source
    // to CLOCK_MONOTONIC but it is already too late.
    //
    // Invalid input event timestamps can result in ANRs, crashes and
    // and other issues that are hard to track down.  We must not let them
    // propagate through the system.
    //
    // Log a warning so that we notice the problem and recover gracefully.
    if (event.when >= currentTime + s2ns(10)) {
        // Double-check. Time may have moved on.
        auto time = systemTime(SYSTEM_TIME_MONOTONIC);
        if (event.when > time) {
            ALOGW("An input event from %s has a timestamp that appears to have "
                    "been generated using the wrong clock source (expected "
                    "CLOCK_MONOTONIC): event time %" PRId64 ", current time %" PRId64
                    ", call time %" PRId64 ". Using current time instead.",
                    mDeviceNode->getPath().c_str(), event.when, time, currentTime);
            event.when = time;
        } else {
            ALOGV("Event time is ok but failed the fast path and required an extra "
                    "call to systemTime: event time %" PRId64 ", current time %" PRId64
                    ", call time %" PRId64 ".", event.when, time, currentTime);
        }
    }

    for (size_t i = 0; i < mMappers.size(); ++i) {
        mMappers[i]->process(event);
    }
}
Beispiel #5
0
bool EventHub::getEvent(int32_t* outDeviceId, int32_t* outType,
        int32_t* outScancode, int32_t* outKeycode, uint32_t *outFlags,
        int32_t* outValue, nsecs_t* outWhen)
{
    *outDeviceId = 0;
    *outType = 0;
    *outScancode = 0;
    *outKeycode = 0;
    *outFlags = 0;
    *outValue = 0;
    *outWhen = 0;

    status_t err;

    fd_set readfds;
    int maxFd = -1;
    int cc;
    int i;
    int res;
    int pollres;
    struct input_event iev;

    // Note that we only allow one caller to getEvent(), so don't need
    // to do locking here...  only when adding/removing devices.

    if (!mOpened) {
        mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR;
        mOpened = true;
    }

    while(1) {

        // First, report any devices that had last been added/removed.
        if (mClosingDevices != NULL) {
            device_t* device = mClosingDevices;
            LOGV("Reporting device closed: id=0x%x, name=%s\n",
                 device->id, device->path.string());
            mClosingDevices = device->next;
            *outDeviceId = device->id;
            if (*outDeviceId == mFirstKeyboardId) *outDeviceId = 0;
            *outType = DEVICE_REMOVED;
            delete device;
            return true;
        }
        if (mOpeningDevices != NULL) {
            device_t* device = mOpeningDevices;
            LOGV("Reporting device opened: id=0x%x, name=%s\n",
                 device->id, device->path.string());
            mOpeningDevices = device->next;
            *outDeviceId = device->id;
            if (*outDeviceId == mFirstKeyboardId) *outDeviceId = 0;
            *outType = DEVICE_ADDED;
            return true;
        }

        release_wake_lock(WAKE_LOCK_ID);

        pollres = poll(mFDs, mFDCount, -1);

        acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);

        if (pollres <= 0) {
            if (errno != EINTR) {
                LOGW("select failed (errno=%d)\n", errno);
                usleep(100000);
            }
            continue;
        }

        //printf("poll %d, returned %d\n", mFDCount, pollres);

        // mFDs[0] is used for inotify, so process regular events starting at mFDs[1]
        for(i = 1; i < mFDCount; i++) {
            if(mFDs[i].revents) {
                LOGV("revents for %d = 0x%08x", i, mFDs[i].revents);
                if(mFDs[i].revents & POLLIN) {
                    res = read(mFDs[i].fd, &iev, sizeof(iev));
                    if (res == sizeof(iev)) {
                        LOGV("%s got: t0=%d, t1=%d, type=%d, code=%d, v=%d",
                             mDevices[i]->path.string(),
                             (int) iev.time.tv_sec, (int) iev.time.tv_usec,
                             iev.type, iev.code, iev.value);
                        *outDeviceId = mDevices[i]->id;
                        if (*outDeviceId == mFirstKeyboardId) *outDeviceId = 0;
                        *outType = iev.type;
                        *outScancode = iev.code;
                        if (iev.type == EV_KEY) {
                            err = mDevices[i]->layoutMap->map(iev.code, outKeycode, outFlags);
                            LOGV("iev.code=%d outKeycode=%d outFlags=0x%08x err=%d\n",
                                iev.code, *outKeycode, *outFlags, err);
                            if (err != 0) {
                                *outKeycode = 0;
                                *outFlags = 0;
                            }
                        } else {
                            *outKeycode = iev.code;
                        }
                        *outValue = iev.value;
                        *outWhen = s2ns(iev.time.tv_sec) + us2ns(iev.time.tv_usec);
                        return true;
                    } else {
                        if (res<0) {
                            LOGW("could not get event (errno=%d)", errno);
                        } else {
                            LOGE("could not get event (wrong size: %d)", res);
                        }
                        continue;
                    }
                }
            }
        }
        
        // read_notify() will modify mFDs and mFDCount, so this must be done after
        // processing all other events.
        if(mFDs[0].revents & POLLIN) {
            read_notify(mFDs[0].fd);
        }
    }
}