Layer.h revision a8bca8d84b559e7dcca010f7d6514333004020c7
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 LayerBaseClient, 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 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 // LayerBaseClient 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 115private: 116 // Creates an instance of ISurface for this Layer. 117 virtual sp<ISurface> createSurface(); 118 119 uint32_t getEffectiveUsage(uint32_t usage) const; 120 bool isCropped() const; 121 static bool getOpacityForFormat(uint32_t format); 122 123 // Interface implementation for SurfaceFlingerConsumer::FrameAvailableListener 124 virtual void onFrameAvailable(); 125 126 // ----------------------------------------------------------------------- 127 128 // constants 129 sp<SurfaceFlingerConsumer> mSurfaceFlingerConsumer; 130 GLuint mTextureName; 131 132 // thread-safe 133 volatile int32_t mQueuedFrames; 134 FrameTracker mFrameTracker; 135 136 // main thread 137 sp<GraphicBuffer> mActiveBuffer; 138 Rect mCurrentCrop; 139 uint32_t mCurrentTransform; 140 uint32_t mCurrentScalingMode; 141 bool mCurrentOpacity; 142 bool mRefreshPending; 143 bool mFrameLatencyNeeded; 144 145 // constants 146 PixelFormat mFormat; 147 const GLExtensions& mGLExtensions; 148 bool mOpaqueLayer; 149 150 // page-flip thread (currently main thread) 151 bool mSecure; // no screenshots 152 bool mProtectedByApp; // application requires protected path to external sink 153}; 154 155// --------------------------------------------------------------------------- 156 157}; // namespace android 158 159#endif // ANDROID_LAYER_H 160