Layer.h revision be48137beb68893870c26b7f8c59eac5d0bf517a
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_H
18#define ANDROID_LAYER_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <ui/GraphicBuffer.h>
24#include <ui/PixelFormat.h>
25#include <pixelflinger/pixelflinger.h>
26
27#include <EGL/egl.h>
28#include <EGL/eglext.h>
29#include <GLES/gl.h>
30#include <GLES/glext.h>
31
32#include "LayerBase.h"
33#include "Transform.h"
34
35namespace android {
36
37// ---------------------------------------------------------------------------
38
39class Client;
40class FreezeLock;
41
42// ---------------------------------------------------------------------------
43
44const size_t NUM_BUFFERS = 2;
45
46class Layer : public LayerBaseClient
47{
48public:
49    static const uint32_t typeInfo;
50    static const char* const typeID;
51    virtual char const* getTypeID() const { return typeID; }
52    virtual uint32_t getTypeInfo() const { return typeInfo; }
53
54                 Layer(SurfaceFlinger* flinger, DisplayID display,
55                         const sp<Client>& client, int32_t i);
56
57        virtual ~Layer();
58
59    status_t setBuffers(uint32_t w, uint32_t h,
60            PixelFormat format, uint32_t flags=0);
61
62    void setDrawingSize(uint32_t w, uint32_t h);
63
64    virtual void onDraw(const Region& clip) const;
65    virtual uint32_t doTransaction(uint32_t transactionFlags);
66    virtual void lockPageFlip(bool& recomputeVisibleRegions);
67    virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
68    virtual void finishPageFlip();
69    virtual bool needsBlending() const      { return mNeedsBlending; }
70    virtual bool needsDithering() const     { return mNeedsDithering; }
71    virtual bool isSecure() const           { return mSecure; }
72    virtual sp<Surface> createSurface() const;
73    virtual status_t ditch();
74
75    // only for debugging
76    inline sp<GraphicBuffer> getBuffer(int i) { return mBuffers[i]; }
77    // only for debugging
78    inline const sp<FreezeLock>&  getFreezeLock() const { return mFreezeLock; }
79    // only for debugging
80    inline PixelFormat pixelFormat() const { return mFormat; }
81    // only for debugging
82    inline int getFrontBufferIndex() const { return mFrontBufferIndex; }
83
84private:
85    inline sp<GraphicBuffer> getFrontBufferLocked() {
86        return mBuffers[mFrontBufferIndex];
87    }
88
89    void reloadTexture(const Region& dirty);
90
91    uint32_t getEffectiveUsage(uint32_t usage) const;
92
93    sp<GraphicBuffer> requestBuffer(int index, int usage);
94    void destroy();
95
96    class SurfaceLayer : public LayerBaseClient::Surface {
97    public:
98        SurfaceLayer(const sp<SurfaceFlinger>& flinger,
99                SurfaceID id, const sp<Layer>& owner);
100        ~SurfaceLayer();
101    private:
102        virtual sp<GraphicBuffer> requestBuffer(int index, int usage);
103        sp<Layer> getOwner() const {
104            return static_cast<Layer*>(Surface::getOwner().get());
105        }
106    };
107    friend class SurfaceLayer;
108
109    sp<Surface>             mSurface;
110
111            bool            mSecure;
112            bool            mNoEGLImageForSwBuffers;
113            int32_t         mFrontBufferIndex;
114            bool            mNeedsBlending;
115            bool            mNeedsDithering;
116            Region          mPostedDirtyRegion;
117            sp<FreezeLock>  mFreezeLock;
118            PixelFormat     mFormat;
119
120            // protected by mLock
121            sp<GraphicBuffer> mBuffers[NUM_BUFFERS];
122            Texture         mTextures[NUM_BUFFERS];
123            sp<GraphicBuffer> mHybridBuffer;
124            uint32_t        mWidth;
125            uint32_t        mHeight;
126
127   mutable Mutex mLock;
128};
129
130// ---------------------------------------------------------------------------
131
132}; // namespace android
133
134#endif // ANDROID_LAYER_H
135