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