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