OSDN Git Service

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