LayerOrientationAnim.h revision 89a187299eeaa9f973ace3dba4916b3fbd36063e
1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_LAYER_ORIENTATION_ANIM_H
18#define ANDROID_LAYER_ORIENTATION_ANIM_H
19
20#include <stdint.h>
21#include <sys/types.h>
22#include <utils/threads.h>
23#include <utils/Parcel.h>
24
25#include "LayerBase.h"
26#include "LayerBitmap.h"
27
28namespace android {
29
30// ---------------------------------------------------------------------------
31class OrientationAnimation;
32
33
34class LayerOrientationAnimBase : public LayerBase
35{
36public:
37    LayerOrientationAnimBase(SurfaceFlinger* flinger, DisplayID display)
38        : LayerBase(flinger, display) {
39    }
40    virtual void onOrientationCompleted() = 0;
41};
42
43// ---------------------------------------------------------------------------
44
45class LayerOrientationAnim : public LayerOrientationAnimBase
46{
47public:
48    static const uint32_t typeInfo;
49    static const char* const typeID;
50    virtual char const* getTypeID() const { return typeID; }
51    virtual uint32_t getTypeInfo() const { return typeInfo; }
52
53                LayerOrientationAnim(SurfaceFlinger* flinger, DisplayID display,
54                        OrientationAnimation* anim,
55                        const LayerBitmap& bitmapIn,
56                        const LayerBitmap& bitmapOut);
57        virtual ~LayerOrientationAnim();
58
59            void onOrientationCompleted();
60
61    virtual void onDraw(const Region& clip) const;
62    virtual Point getPhysicalSize() const;
63    virtual void validateVisibility(const Transform& globalTransform);
64    virtual bool needsBlending() const;
65    virtual bool isSecure() const       { return false; }
66private:
67    void drawScaled(float scale, float alphaIn, float alphaOut) const;
68
69    class Lerp {
70        float in;
71        float outMinusIn;
72    public:
73        Lerp() : in(0), outMinusIn(0) { }
74        Lerp(float in, float out) : in(in), outMinusIn(out-in) { }
75        float getIn() const { return in; };
76        float getOut() const { return in + outMinusIn; }
77        void set(float in, float out) {
78            this->in = in;
79            this->outMinusIn = out-in;
80        }
81        void setIn(float in) {
82            this->in = in;
83        }
84        void setOut(float out) {
85            this->outMinusIn = out - this->in;
86        }
87        float operator()(float t) const {
88            return outMinusIn*t + in;
89        }
90    };
91
92    OrientationAnimation* mAnim;
93    LayerBitmap mBitmapIn;
94    LayerBitmap mBitmapOut;
95    nsecs_t mStartTime;
96    nsecs_t mFinishTime;
97    bool mOrientationCompleted;
98    mutable bool mFirstRedraw;
99    mutable float mLastNormalizedTime;
100    mutable GLuint  mTextureName;
101    mutable GLuint  mTextureNameIn;
102    mutable bool mNeedsBlending;
103
104    mutable Lerp mAlphaInLerp;
105    mutable Lerp mAlphaOutLerp;
106};
107
108// ---------------------------------------------------------------------------
109
110}; // namespace android
111
112#endif // ANDROID_LAYER_ORIENTATION_ANIM_H
113