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