Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c2bcbc6 authored by The Android Open Source Project's avatar The Android Open Source Project
Browse files

auto import from //branches/cupcake_rel/...@141571

parent 4f68be1a
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -42,7 +42,8 @@ LOCAL_SRC_FILES:= \
LOCAL_SHARED_LIBRARIES:= \
LOCAL_SHARED_LIBRARIES:= \
    libui \
    libui \
    libutils \
    libutils \
    libcutils
    libcutils \
    libmedia


LOCAL_MODULE:= libcameraservice
LOCAL_MODULE:= libcameraservice


+30 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,8 @@
#include <utils/MemoryHeapBase.h>
#include <utils/MemoryHeapBase.h>
#include <ui/ICameraService.h>
#include <ui/ICameraService.h>


#include <media/mediaplayer.h>
#include <media/AudioSystem.h>
#include "CameraService.h"
#include "CameraService.h"


namespace android {
namespace android {
@@ -151,6 +153,19 @@ void CameraService::removeClient(const sp<ICameraClient>& cameraClient)
    }
    }
}
}


static sp<MediaPlayer> newMediaPlayer(const char *file) 
{
    sp<MediaPlayer> mp = new MediaPlayer();
    if (mp->setDataSource(file) == NO_ERROR) {
        mp->setAudioStreamType(AudioSystem::ALARM);
        mp->prepare();
    } else {
        mp.clear();
        LOGE("Failed to load CameraService sounds.");
    }
    return mp;
}

CameraService::Client::Client(const sp<CameraService>& cameraService,
CameraService::Client::Client(const sp<CameraService>& cameraService,
        const sp<ICameraClient>& cameraClient, pid_t clientPid)
        const sp<ICameraClient>& cameraClient, pid_t clientPid)
{
{
@@ -161,6 +176,9 @@ CameraService::Client::Client(const sp<CameraService>& cameraService,
    mHardware = openCameraHardware();
    mHardware = openCameraHardware();
    mUseOverlay = mHardware->useOverlay();
    mUseOverlay = mHardware->useOverlay();


    mMediaPlayerClick = newMediaPlayer("/system/media/audio/ui/camera_click.ogg");
    mMediaPlayerBeep = newMediaPlayer("/system/media/audio/ui/VideoRecord.ogg");

    // Callback is disabled by default
    // Callback is disabled by default
    mPreviewCallbackFlag = FRAME_CALLBACK_FLAG_NOOP;
    mPreviewCallbackFlag = FRAME_CALLBACK_FLAG_NOOP;
    LOGD("Client X constructor");
    LOGD("Client X constructor");
@@ -265,6 +283,9 @@ CameraService::Client::~Client()
#endif
#endif
    }
    }


    mMediaPlayerBeep.clear();
    mMediaPlayerClick.clear();

    // make sure we tear down the hardware
    // make sure we tear down the hardware
    mClientPid = IPCThreadState::self()->getCallingPid();
    mClientPid = IPCThreadState::self()->getCallingPid();
    disconnect();
    disconnect();
@@ -464,6 +485,9 @@ status_t CameraService::Client::startPreview()


status_t CameraService::Client::startRecording()
status_t CameraService::Client::startRecording()
{
{
    if (mMediaPlayerBeep.get() != NULL) {
        mMediaPlayerBeep->start();
    }
    return startCameraMode(CAMERA_RECORDING_MODE);
    return startCameraMode(CAMERA_RECORDING_MODE);
}
}


@@ -502,6 +526,9 @@ void CameraService::Client::stopRecording()
        return;
        return;
    }
    }


    if (mMediaPlayerBeep.get() != NULL) {
        mMediaPlayerBeep->start();
    }
    mHardware->stopRecording();
    mHardware->stopRecording();
    LOGV("stopRecording(), hardware stopped OK");
    LOGV("stopRecording(), hardware stopped OK");
    mPreviewBuffer.clear();
    mPreviewBuffer.clear();
@@ -684,6 +711,9 @@ status_t CameraService::Client::takePicture()
        return INVALID_OPERATION;
        return INVALID_OPERATION;
    }
    }


    if (mMediaPlayerClick.get() != NULL) {
        mMediaPlayerClick->start();
    }
    return mHardware->takePicture(shutterCallback,
    return mHardware->takePicture(shutterCallback,
                                  yuvPictureCallback,
                                  yuvPictureCallback,
                                  jpegPictureCallback,
                                  jpegPictureCallback,
+5 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,8 @@ class android::MemoryHeapBase;


namespace android {
namespace android {


class MediaPlayer;

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


#define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
#define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
@@ -178,6 +180,9 @@ private:
                    sp<MemoryHeapBase>          mPreviewBuffer;
                    sp<MemoryHeapBase>          mPreviewBuffer;
                    int                         mPreviewCallbackFlag;
                    int                         mPreviewCallbackFlag;


                    sp<MediaPlayer>             mMediaPlayerClick;
                    sp<MediaPlayer>             mMediaPlayerBeep;

                    // these are immutable once the object is created,
                    // these are immutable once the object is created,
                    // they don't need to be protected by a lock
                    // they don't need to be protected by a lock
                    sp<ICameraClient>           mCameraClient;
                    sp<ICameraClient>           mCameraClient;
+20 −179
Original line number Original line Diff line number Diff line
@@ -187,44 +187,20 @@ bool BootAnimation::threadLoop() {
}
}


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

    // erase screen
    glDisable(GL_SCISSOR_TEST);
    glBindTexture(GL_TEXTURE_2D, mAndroid[0].name);


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


    // wait ~1s
    // wait ~1s
    usleep(800000);


    // fade in
    const GLint xc = (mWidth  - mAndroid[0].w) / 2;
    glEnable(GL_BLEND);
    const GLint yc = (mHeight - mAndroid[0].h) / 2;
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h);
    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    const int steps = 8;
    for (int i = 1; i < steps; i++) {
        float fade = i / float(steps);
        glColor4f(1, 1, 1, fade * fade);
        glClear(GL_COLOR_BUFFER_BIT);
        glDrawTexiOES(0, 0, 0, mAndroid[0].w, mAndroid[0].h);
        eglSwapBuffers(mDisplay, mSurface);
    }

    // draw last frame
    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glDisable(GL_BLEND);
    glDrawTexiOES(0, 0, 0, mAndroid[0].w, mAndroid[0].h);
    eglSwapBuffers(mDisplay, mSurface);

    // update rect for the robot
    const int x = mWidth - mAndroid[1].w - 33;
    const int y = (mHeight - mAndroid[1].h) / 2 - 1;
    const Rect updateRect(x, y, x + mAndroid[1].w, y + mAndroid[1].h);


    // draw and update only what we need
    // draw and update only what we need
    mNativeWindowSurface->setSwapRectangle(updateRect.left,
    mNativeWindowSurface->setSwapRectangle(updateRect.left,
@@ -234,166 +210,31 @@ bool BootAnimation::android() {
    glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(),
    glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(),
            updateRect.height());
            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();
    const nsecs_t startTime = systemTime();
    do {
    do {
        // glow speed and shape
        double time = systemTime() - startTime;
        nsecs_t time = systemTime() - startTime;
        float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w;
        float t = ((4.0f / (360.0f * us2ns(16667))) * time);
        GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w;
        t = t - floorf(t);
        GLint x = xc - offset;
        const float fade = 0.5f + 0.5f * sinf(t * 2 * M_PI);


        // fade the glow in and out
        glDisable(GL_BLEND);
        glDisable(GL_BLEND);
        glBindTexture(GL_TEXTURE_2D, mAndroid[2].name);
        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        glColor4f(fade, fade, fade, fade);
        glDrawTexiOES(updateRect.left, mHeight - updateRect.bottom, 0,
                updateRect.width(), updateRect.height());

        // draw the robot
        glEnable(GL_BLEND);
        glBindTexture(GL_TEXTURE_2D, mAndroid[1].name);
        glBindTexture(GL_TEXTURE_2D, mAndroid[1].name);
        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
        glDrawTexiOES(x,                 yc, 0, mAndroid[1].w, mAndroid[1].h);
        glDrawTexiOES(updateRect.left, mHeight - updateRect.bottom, 0,
        glDrawTexiOES(x + mAndroid[1].w, yc, 0, mAndroid[1].w, mAndroid[1].h);
                updateRect.width(), updateRect.height());


        // make sure sleep a lot to not take too much CPU away from 
        glEnable(GL_BLEND);
        // the boot process. With this "glow" animation there is no
        glBindTexture(GL_TEXTURE_2D, mAndroid[0].name);
        // visible difference. 
        glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h);
        usleep(16667 * 4);


        eglSwapBuffers(mDisplay, mSurface);
        eglSwapBuffers(mDisplay, mSurface);
    } while (!exitPending());
    } while (!exitPending());


    glDeleteTextures(1, &mAndroid[0].name);
    glDeleteTextures(1, &mAndroid[0].name);
    glDeleteTextures(1, &mAndroid[1].name);
    glDeleteTextures(1, &mAndroid[1].name);
    glDeleteTextures(1, &mAndroid[2].name);
    return false;
}

bool BootAnimation::cylon() {
    // initialize the textures...
    initTexture(&mLeftTrail, mAssets, "images/cylon_left.png");
    initTexture(&mRightTrail, mAssets, "images/cylon_right.png");
    initTexture(&mBrightSpot, mAssets, "images/cylon_dot.png");

    int w = mWidth;
    int h = mHeight;

    const Point c(w / 2, h / 2);
    const GLint amplitude = 60;
    const int scx = c.x - amplitude - mBrightSpot.w / 2;
    const int scy = c.y - mBrightSpot.h / 2;
    const int scw = amplitude * 2 + mBrightSpot.w;
    const int sch = mBrightSpot.h;
    const Rect updateRect(scx, h - scy - sch, scx + scw, h - scy);

    // erase screen
    glDisable(GL_SCISSOR_TEST);
    glClear(GL_COLOR_BUFFER_BIT);

    eglSwapBuffers(mDisplay, mSurface);

    glClear(GL_COLOR_BUFFER_BIT);

    mNativeWindowSurface->setSwapRectangle(updateRect.left,
            updateRect.top, updateRect.width(), updateRect.height());

    glEnable(GL_SCISSOR_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

    // clear the screen to white
    Point p;
    float t = 0;
    float alpha = 1.0f;
    const nsecs_t startTime = systemTime();
    nsecs_t fadeTime = 0;

    do {
        // Set scissor in interesting area
        glScissor(scx, scy, scw, sch);

        // erase screen
        glClear(GL_COLOR_BUFFER_BIT);

        // compute wave
        const float a = (t * 2 * M_PI) - M_PI / 2;
        const float sn = sinf(a);
        const float cs = cosf(a);
        GLint x = GLint(amplitude * sn);
        float derivative = cs;

        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

        if (derivative > 0) {
            // vanishing trail...
            p.x = (-amplitude + c.x) - mBrightSpot.w / 2;
            p.y = c.y - mLeftTrail.h / 2;
            float fade = 2.0f * (0.5f - t);
            //fade *= fade;
            glColor4f(fade, fade, fade, fade);
            glBindTexture(GL_TEXTURE_2D, mLeftTrail.name);
            glDrawTexiOES(p.x, p.y, 0, mLeftTrail.w, mLeftTrail.h);

            // trail...
            p.x = (x + c.x) - (mRightTrail.w + mBrightSpot.w / 2) + 16;
            p.y = c.y - mRightTrail.h / 2;
            fade = t < 0.25f ? t * 4.0f : 1.0f;
            fade *= fade;
            glColor4f(fade, fade, fade, fade);
            glBindTexture(GL_TEXTURE_2D, mRightTrail.name);
            glDrawTexiOES(p.x, p.y, 0, mRightTrail.w, mRightTrail.h);
        } else {
            // vanishing trail..
            p.x = (amplitude + c.x) - (mRightTrail.w + mBrightSpot.w / 2) + 16;
            p.y = c.y - mRightTrail.h / 2;
            float fade = 2.0f * (0.5f - (t - 0.5f));
            //fade *= fade;
            glColor4f(fade, fade, fade, fade);
            glBindTexture(GL_TEXTURE_2D, mRightTrail.name);
            glDrawTexiOES(p.x, p.y, 0, mRightTrail.w, mRightTrail.h);

            // trail...
            p.x = (x + c.x) - mBrightSpot.w / 2;
            p.y = c.y - mLeftTrail.h / 2;
            fade = t < 0.5f + 0.25f ? (t - 0.5f) * 4.0f : 1.0f;
            fade *= fade;
            glColor4f(fade, fade, fade, fade);
            glBindTexture(GL_TEXTURE_2D, mLeftTrail.name);
            glDrawTexiOES(p.x, p.y, 0, mLeftTrail.w, mLeftTrail.h);
        }

        const Point p(x + c.x - mBrightSpot.w / 2, c.y - mBrightSpot.h / 2);
        glBindTexture(GL_TEXTURE_2D, mBrightSpot.name);
        glColor4f(1, 0.5, 0.5, 1);
        glDrawTexiOES(p.x, p.y, 0, mBrightSpot.w, mBrightSpot.h);

        // update animation
        nsecs_t time = systemTime() - startTime;
        t = ((4.0f / (360.0f * us2ns(16667))) * time);
        t = t - floorf(t);

        eglSwapBuffers(mDisplay, mSurface);

        if (exitPending()) {
            if (fadeTime == 0) {
                fadeTime = time;
            }
            time -= fadeTime;
            alpha = 1.0f - ((float(time) * 6.0f) / float(s2ns(1)));

            session()->openTransaction();
            mFlingerSurface->setAlpha(alpha * alpha);
            session()->closeTransaction();
        }
    } while (alpha > 0);

    // cleanup
    glFinish();
    glDeleteTextures(1, &mLeftTrail.name);
    glDeleteTextures(1, &mRightTrail.name);
    glDeleteTextures(1, &mBrightSpot.name);
    return false;
    return false;
}
}


+3 −7
Original line number Original line Diff line number Diff line
@@ -62,14 +62,10 @@ private:


    status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
    status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
    bool android();
    bool android();
    bool cylon();


    sp<SurfaceComposerClient>       mSession;
    sp<SurfaceComposerClient>       mSession;
    AssetManager mAssets;
    AssetManager mAssets;
    Texture mLeftTrail;
    Texture     mAndroid[2];
    Texture mRightTrail;
    Texture mBrightSpot;
    Texture mAndroid[3];
    int         mWidth;
    int         mWidth;
    int         mHeight;
    int         mHeight;
    EGLDisplay  mDisplay;
    EGLDisplay  mDisplay;
Loading