DisplayDevice.h revision d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3
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_DISPLAY_DEVICE_H 18#define ANDROID_DISPLAY_DEVICE_H 19 20#include <stdlib.h> 21 22#include <ui/PixelFormat.h> 23#include <ui/Region.h> 24 25#include <EGL/egl.h> 26#include <EGL/eglext.h> 27 28#include <utils/Mutex.h> 29#include <utils/Timers.h> 30 31#include "Transform.h" 32 33namespace android { 34 35class DisplayInfo; 36class FramebufferSurface; 37class LayerBase; 38class SurfaceFlinger; 39class SurfaceTextureClient; 40 41class DisplayDevice 42{ 43public: 44 // region in layer-stack space 45 mutable Region dirtyRegion; 46 // region in screen space 47 mutable Region swapRegion; 48 // region in screen space 49 Region undefinedRegion; 50 51 enum { 52 PARTIAL_UPDATES = 0x00020000, // video driver feature 53 SWAP_RECTANGLE = 0x00080000, 54 }; 55 56 DisplayDevice( 57 const sp<SurfaceFlinger>& flinger, 58 int dpy, 59 const sp<SurfaceTextureClient>& surface, 60 EGLConfig config); 61 62 ~DisplayDevice(); 63 64 // Flip the front and back buffers if the back buffer is "dirty". Might 65 // be instantaneous, might involve copying the frame buffer around. 66 void flip(const Region& dirty) const; 67 68 float getDpiX() const; 69 float getDpiY() const; 70 float getRefreshRate() const; 71 float getDensity() const; 72 int getWidth() const; 73 int getHeight() const; 74 PixelFormat getFormat() const; 75 uint32_t getFlags() const; 76 nsecs_t getRefreshPeriod() const; 77 status_t getInfo(DisplayInfo* info) const; 78 79 EGLSurface getEGLSurface() const; 80 81 void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers); 82 Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const; 83 bool getSecureLayerVisible() const; 84 85 status_t setOrientation(int orientation); 86 int getOrientation() const { return mOrientation; } 87 const Transform& getTransform() const { return mGlobalTransform; } 88 uint32_t getLayerStack() const { return mLayerStack; } 89 90 status_t compositionComplete() const; 91 92 Rect getBounds() const { 93 return Rect(mDisplayWidth, mDisplayHeight); 94 } 95 inline Rect bounds() const { return getBounds(); } 96 97 static void makeCurrent(const DisplayDevice& hw, EGLContext ctx); 98 99 /* ------------------------------------------------------------------------ 100 * blank / unplank management 101 */ 102 void releaseScreen() const; 103 void acquireScreen() const; 104 bool isScreenAcquired() const; 105 bool canDraw() const; 106 107 /* ------------------------------------------------------------------------ 108 * Debugging 109 */ 110 uint32_t getPageFlipCount() const; 111 void dump(String8& res) const; 112 113 114private: 115 void init(EGLConfig config); 116 117 /* 118 * Constants, set during initialization 119 */ 120 sp<SurfaceFlinger> mFlinger; 121 int mDisplayId; 122 123 // ANativeWindow this display is rendering into 124 sp<SurfaceTextureClient> mNativeWindow; 125 126 // set if mNativeWindow is a FramebufferSurface 127 sp<FramebufferSurface> mFramebufferSurface; 128 129 EGLDisplay mDisplay; 130 EGLSurface mSurface; 131 EGLContext mContext; 132 float mDpiX; 133 float mDpiY; 134 float mRefreshRate; 135 float mDensity; 136 int mDisplayWidth; 137 int mDisplayHeight; 138 PixelFormat mFormat; 139 uint32_t mFlags; 140 mutable uint32_t mPageFlipCount; 141 nsecs_t mRefreshPeriod; 142 143 /* 144 * Can only accessed from the main thread, these members 145 * don't need synchronization. 146 */ 147 148 // list of visible layers on that display 149 Vector< sp<LayerBase> > mVisibleLayersSortedByZ; 150 151 // Whether we have a visible secure layer on this display 152 bool mSecureLayerVisible; 153 154 // Whether the screen is blanked; 155 mutable int mScreenAcquired; 156 157 158 /* 159 * Transaction state 160 */ 161 static status_t orientationToTransfrom(int orientation, int w, int h, 162 Transform* tr); 163 Transform mGlobalTransform; 164 int mOrientation; 165 uint32_t mLayerStack; 166}; 167 168}; // namespace android 169 170#endif // ANDROID_DISPLAY_DEVICE_H 171