Layer.h revision 99ce5cdeb383216dee95af4d90e47406b0948ea1
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 <gui/SurfaceTexture.h>
24
25#include <pixelflinger/pixelflinger.h>
26#include <ui/GraphicBuffer.h>
27#include <ui/PixelFormat.h>
28
29#include <EGL/egl.h>
30#include <EGL/eglext.h>
31#include <GLES/gl.h>
32#include <GLES/glext.h>
33
34#include "LayerBase.h"
35#include "SurfaceTextureLayer.h"
36#include "Transform.h"
37#include <utils/Timers.h>
38
39namespace android {
40
41// ---------------------------------------------------------------------------
42
43class Client;
44class GLExtensions;
45
46// ---------------------------------------------------------------------------
47
48class Layer : public LayerBaseClient
49{
50public:
51            Layer(SurfaceFlinger* flinger, DisplayID display,
52                    const sp<Client>& client);
53
54    virtual ~Layer();
55
56    virtual const char* getTypeId() const { return "Layer"; }
57
58    // the this layer's size and format
59    status_t setBuffers(uint32_t w, uint32_t h,
60            PixelFormat format, uint32_t flags=0);
61
62    bool isFixedSize() const;
63
64    // LayerBase interface
65    virtual void setGeometry(hwc_layer_t* hwcl);
66    virtual void setPerFrameData(hwc_layer_t* hwcl);
67    virtual void onDraw(const Region& clip) const;
68    virtual uint32_t doTransaction(uint32_t transactionFlags);
69    virtual void lockPageFlip(bool& recomputeVisibleRegions);
70    virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
71    virtual bool isOpaque() const;
72    virtual bool needsDithering() const     { return mNeedsDithering; }
73    virtual bool isSecure() const           { return mSecure; }
74    virtual bool isProtected() const;
75    virtual void onRemoved();
76    virtual sp<Layer> getLayer() const { return const_cast<Layer*>(this); }
77    virtual void setName(const String8& name);
78
79    // LayerBaseClient interface
80    virtual wp<IBinder> getSurfaceTextureBinder() const;
81
82    virtual void onLayerDisplayed();
83    virtual bool onPreComposition();
84
85    // only for debugging
86    inline const sp<GraphicBuffer>& getActiveBuffer() const { return mActiveBuffer; }
87
88protected:
89    virtual void onFirstRef();
90    virtual void dump(String8& result, char* scratch, size_t size) const;
91    virtual void dumpStats(String8& result, char* buffer, size_t SIZE) const;
92    virtual void clearStats();
93
94private:
95    friend class SurfaceTextureLayer;
96    void onFrameQueued();
97    virtual sp<ISurface> createSurface();
98    uint32_t getEffectiveUsage(uint32_t usage) const;
99    uint32_t getTransformHint() const;
100    bool isCropped() const;
101    static bool getOpacityForFormat(uint32_t format);
102
103    // -----------------------------------------------------------------------
104
105    // constants
106    sp<SurfaceTextureLayer> mSurfaceTexture;
107    GLuint mTextureName;
108
109    // thread-safe
110    volatile int32_t mQueuedFrames;
111
112    // main thread
113    sp<GraphicBuffer> mActiveBuffer;
114    GLfloat mTextureMatrix[16];
115    Rect mCurrentCrop;
116    uint32_t mCurrentTransform;
117    uint32_t mCurrentScalingMode;
118    bool mCurrentOpacity;
119    size_t mRefreshPending;
120    bool mFrameLatencyNeeded;
121    int mFrameLatencyOffset;
122
123    struct Statistics {
124        Statistics() : timestamp(0), set(0), vsync(0) { }
125        nsecs_t timestamp;  // buffer timestamp
126        nsecs_t set;        // buffer displayed timestamp
127        nsecs_t vsync;      // vsync immediately before set
128    };
129
130    // protected by mLock
131    Statistics mFrameStats[128];
132
133    // constants
134    PixelFormat mFormat;
135    const GLExtensions& mGLExtensions;
136    bool mOpaqueLayer;
137    bool mNeedsDithering;
138
139    // page-flip thread (currently main thread)
140    bool mSecure;         // no screenshots
141    bool mProtectedByApp; // application requires protected path to external sink
142    Region mPostedDirtyRegion;
143};
144
145// ---------------------------------------------------------------------------
146
147}; // namespace android
148
149#endif // ANDROID_LAYER_H
150