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 <ui/PixelFormat.h> 24 25#include <private/ui/SharedState.h> 26#include <private/ui/LayerState.h> 27 28#include <pixelflinger/pixelflinger.h> 29 30#include "LayerBitmap.h" 31#include "LayerBase.h" 32#include "Transform.h" 33 34namespace android { 35 36// --------------------------------------------------------------------------- 37 38class Client; 39class LayerBitmap; 40class MemoryDealer; 41class FreezeLock; 42 43// --------------------------------------------------------------------------- 44 45class Layer : public LayerBaseClient 46{ 47public: 48 static const uint32_t typeInfo; 49 static const char* const typeID; 50 virtual char const* getTypeID() const { return typeID; } 51 virtual uint32_t getTypeInfo() const { return typeInfo; } 52 53 Layer(SurfaceFlinger* flinger, DisplayID display, 54 Client* c, int32_t i); 55 56 virtual ~Layer(); 57 58 inline PixelFormat pixelFormat() const { 59 return frontBuffer().pixelFormat(); 60 } 61 62 status_t setBuffers( Client* client, 63 uint32_t w, uint32_t h, 64 PixelFormat format, uint32_t flags=0); 65 66 virtual void onDraw(const Region& clip) const; 67 virtual void initStates(uint32_t w, uint32_t h, uint32_t flags); 68 virtual void setSizeChanged(uint32_t w, uint32_t h); 69 virtual uint32_t doTransaction(uint32_t transactionFlags); 70 virtual Point getPhysicalSize() const; 71 virtual void lockPageFlip(bool& recomputeVisibleRegions); 72 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion); 73 virtual void finishPageFlip(); 74 virtual bool needsBlending() const { return mNeedsBlending; } 75 virtual bool isSecure() const { return mSecure; } 76 virtual GLuint getTextureName() const { return mTextureName; } 77 virtual sp<Surface> getSurface() const; 78 79 const LayerBitmap& getBuffer(int i) const { return mBuffers[i]; } 80 LayerBitmap& getBuffer(int i) { return mBuffers[i]; } 81 82 // only for debugging 83 const sp<FreezeLock>& getFreezeLock() const { return mFreezeLock; } 84 85private: 86 inline const LayerBitmap& 87 frontBuffer() const { return getBuffer(mFrontBufferIndex); } 88 inline LayerBitmap& 89 frontBuffer() { return getBuffer(mFrontBufferIndex); } 90 inline const LayerBitmap& 91 backBuffer() const { return getBuffer(1-mFrontBufferIndex); } 92 inline LayerBitmap& 93 backBuffer() { return getBuffer(1-mFrontBufferIndex); } 94 95 void reloadTexture(const Region& dirty); 96 97 status_t resize(int32_t index, uint32_t w, uint32_t h, const char* what); 98 Region post(uint32_t* oldState, bool& recomputeVisibleRegions); 99 status_t reallocateBuffer(int32_t index, uint32_t w, uint32_t h); 100 101 sp<Surface> mSurface; 102 103 bool mSecure; 104 LayerBitmap mBuffers[2]; 105 int32_t mFrontBufferIndex; 106 bool mNeedsBlending; 107 bool mResizeTransactionDone; 108 Region mPostedDirtyRegion; 109 sp<FreezeLock> mFreezeLock; 110 111 GLuint mTextureName; 112 GLuint mTextureWidth; 113 GLuint mTextureHeight; 114}; 115 116// --------------------------------------------------------------------------- 117 118}; // namespace android 119 120#endif // ANDROID_LAYER_H 121