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