summaryrefslogtreecommitdiffstats
path: root/libs/surfaceflinger/Layer.h
blob: dc03d35f848e9fc8f66ef6f70e42201c5310e159 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_LAYER_H
#define ANDROID_LAYER_H

#include <stdint.h>
#include <sys/types.h>

#include <ui/PixelFormat.h>

#include <private/ui/SharedState.h>
#include <private/ui/LayerState.h>

#include <pixelflinger/pixelflinger.h>

#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES/gl.h>
#include <GLES/glext.h>

#include "LayerBitmap.h"
#include "LayerBase.h"
#include "Transform.h"

namespace android {

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

class Client;
class LayerBitmap;
class MemoryDealer;
class FreezeLock;

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

const int NUM_BUFFERS = 2;

class Layer : public LayerBaseClient
{
public:    
    static const uint32_t typeInfo;
    static const char* const typeID;
    virtual char const* getTypeID() const { return typeID; }
    virtual uint32_t getTypeInfo() const { return typeInfo; }

                 Layer(SurfaceFlinger* flinger, DisplayID display,
                         Client* c, int32_t i);

        virtual ~Layer();

    inline PixelFormat pixelFormat() const {
        return frontBuffer().getPixelFormat();
    }

    status_t setBuffers(    Client* client,
                            uint32_t w, uint32_t h,
                            PixelFormat format, uint32_t flags=0);

    virtual void onDraw(const Region& clip) const;
    virtual void initStates(uint32_t w, uint32_t h, uint32_t flags);
    virtual void setSizeChanged(uint32_t w, uint32_t h);
    virtual uint32_t doTransaction(uint32_t transactionFlags);
    virtual Point getPhysicalSize() const;
    virtual void lockPageFlip(bool& recomputeVisibleRegions);
    virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
    virtual void finishPageFlip();
    virtual bool needsBlending() const      { return mNeedsBlending; }
    virtual bool isSecure() const           { return mSecure; }
    virtual sp<Surface> createSurface() const;

    const LayerBitmap& getBuffer(int i) const { return mBuffers[i]; }
          LayerBitmap& getBuffer(int i)       { return mBuffers[i]; }

    // only for debugging
    const sp<FreezeLock>&  getFreezeLock() const { return mFreezeLock; }

private:
    inline const LayerBitmap&
            frontBuffer() const { return getBuffer(mFrontBufferIndex); }
    inline LayerBitmap&
            frontBuffer()       { return getBuffer(mFrontBufferIndex); }
    inline const LayerBitmap&
            backBuffer() const  { return getBuffer(1-mFrontBufferIndex); }
    inline LayerBitmap&
            backBuffer()        { return getBuffer(1-mFrontBufferIndex); }

    void reloadTexture(const Region& dirty);

    status_t resize(int32_t index, uint32_t w, uint32_t h, const char* what);
    Region post(uint32_t* oldState, bool& recomputeVisibleRegions);
    sp<SurfaceBuffer> peekBuffer();
    
    
    class SurfaceLayer : public LayerBaseClient::Surface
    {
    public:
                SurfaceLayer(SurfaceID id, const sp<Layer>& owner);

    private:
        virtual sp<SurfaceBuffer> getBuffer();

        sp<Layer> getOwner() const {
            return static_cast<Layer*>(Surface::getOwner().get());
        }
    };
    friend class SurfaceLayer;
    
    struct Texture {
        Texture() : name(-1U), width(0), height(0), image(EGL_NO_IMAGE_KHR),
            dirty(true) { }
        GLuint      name;
        GLuint      width;
        GLuint      height;
        EGLImageKHR image;
        bool        dirty;
    };
    
    sp<Surface>             mSurface;

            bool            mSecure;
            LayerBitmap     mBuffers[NUM_BUFFERS];
            Texture         mTextures[NUM_BUFFERS];
            int32_t         mFrontBufferIndex;
            bool            mNeedsBlending;
            bool            mResizeTransactionDone;
            Region          mPostedDirtyRegion;
            sp<FreezeLock>  mFreezeLock;
};

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

}; // namespace android

#endif // ANDROID_LAYER_H