The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_DISPLAY_DEVICE_H |
| 18 | #define ANDROID_DISPLAY_DEVICE_H |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | |
| 20 | #include <stdlib.h> |
| 21 | |
| 22 | #include <ui/PixelFormat.h> |
| 23 | #include <ui/Region.h> |
| 24 | |
| 25 | #include <EGL/egl.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 26 | #include <EGL/eglext.h> |
| 27 | |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 28 | #include <utils/Mutex.h> |
| 29 | #include <utils/Timers.h> |
| 30 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 31 | #include "Transform.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 32 | |
Mathias Agopian | d8552d7 | 2012-08-04 21:39:11 -0700 | [diff] [blame^] | 33 | struct ANativeWindow; |
| 34 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | namespace android { |
| 36 | |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 37 | class DisplayInfo; |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 38 | class FramebufferSurface; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 39 | class LayerBase; |
| 40 | class SurfaceFlinger; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 42 | class DisplayDevice |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | { |
| 44 | public: |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 45 | // region in layer-stack space |
| 46 | mutable Region dirtyRegion; |
| 47 | // region in screen space |
| 48 | mutable Region swapRegion; |
| 49 | // region in screen space |
| 50 | Region undefinedRegion; |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 51 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | enum { |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 53 | DISPLAY_ID_MAIN = 0, |
| 54 | DISPLAY_ID_HDMI = 1 |
| 55 | }; |
| 56 | |
| 57 | enum { |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 58 | PARTIAL_UPDATES = 0x00020000, // video driver feature |
| 59 | SWAP_RECTANGLE = 0x00080000, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 62 | DisplayDevice(); |
| 63 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 64 | DisplayDevice( |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | const sp<SurfaceFlinger>& flinger, |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 66 | int dpy, |
Mathias Agopian | d8552d7 | 2012-08-04 21:39:11 -0700 | [diff] [blame^] | 67 | const sp<ANativeWindow>& surface, |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 68 | EGLConfig config); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 70 | ~DisplayDevice(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 72 | // must be called when this object is no longer needed. this will |
| 73 | // render the associated EGLSurface invalid. |
| 74 | void terminate(); |
| 75 | |
| 76 | // whether this is a valid object. An invalid DisplayDevice is returned |
| 77 | // when an non existing id is requested |
| 78 | bool isValid() const; |
| 79 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | // Flip the front and back buffers if the back buffer is "dirty". Might |
| 81 | // be instantaneous, might involve copying the frame buffer around. |
| 82 | void flip(const Region& dirty) const; |
| 83 | |
| 84 | float getDpiX() const; |
| 85 | float getDpiY() const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | float getDensity() const; |
| 87 | int getWidth() const; |
| 88 | int getHeight() const; |
| 89 | PixelFormat getFormat() const; |
| 90 | uint32_t getFlags() const; |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 91 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 92 | EGLSurface getEGLSurface() const; |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 93 | |
| 94 | void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers); |
| 95 | Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const; |
| 96 | bool getSecureLayerVisible() const; |
| 97 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 98 | status_t setOrientation(int orientation); |
| 99 | int getOrientation() const { return mOrientation; } |
| 100 | const Transform& getTransform() const { return mGlobalTransform; } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 101 | uint32_t getLayerStack() const { return mLayerStack; } |
| 102 | |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 103 | status_t compositionComplete() const; |
| 104 | |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 105 | Rect getBounds() const { |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 106 | return Rect(mDisplayWidth, mDisplayHeight); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | } |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 108 | inline Rect bounds() const { return getBounds(); } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 110 | static void makeCurrent(const DisplayDevice& hw, EGLContext ctx); |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 111 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 112 | /* ------------------------------------------------------------------------ |
| 113 | * blank / unplank management |
| 114 | */ |
| 115 | void releaseScreen() const; |
| 116 | void acquireScreen() const; |
| 117 | bool isScreenAcquired() const; |
| 118 | bool canDraw() const; |
| 119 | |
| 120 | /* ------------------------------------------------------------------------ |
| 121 | * Debugging |
| 122 | */ |
| 123 | uint32_t getPageFlipCount() const; |
| 124 | void dump(String8& res) const; |
| 125 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 126 | inline bool operator < (const DisplayDevice& rhs) const { |
| 127 | return mId < rhs.mId; |
| 128 | } |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 129 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | private: |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 131 | void init(EGLConfig config); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 133 | /* |
| 134 | * Constants, set during initialization |
| 135 | */ |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 136 | sp<SurfaceFlinger> mFlinger; |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 137 | int32_t mId; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 138 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 139 | // ANativeWindow this display is rendering into |
Mathias Agopian | d8552d7 | 2012-08-04 21:39:11 -0700 | [diff] [blame^] | 140 | sp<ANativeWindow> mNativeWindow; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 141 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 142 | // set if mNativeWindow is a FramebufferSurface |
| 143 | sp<FramebufferSurface> mFramebufferSurface; |
| 144 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | EGLDisplay mDisplay; |
| 146 | EGLSurface mSurface; |
| 147 | EGLContext mContext; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | float mDpiX; |
| 149 | float mDpiY; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | float mDensity; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 151 | int mDisplayWidth; |
| 152 | int mDisplayHeight; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | PixelFormat mFormat; |
| 154 | uint32_t mFlags; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 155 | mutable uint32_t mPageFlipCount; |
Mathias Agopian | 03e4072 | 2012-04-26 16:11:59 -0700 | [diff] [blame] | 156 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 157 | /* |
| 158 | * Can only accessed from the main thread, these members |
| 159 | * don't need synchronization. |
| 160 | */ |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 161 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 162 | // list of visible layers on that display |
| 163 | Vector< sp<LayerBase> > mVisibleLayersSortedByZ; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 164 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 165 | // Whether we have a visible secure layer on this display |
| 166 | bool mSecureLayerVisible; |
| 167 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 168 | // Whether the screen is blanked; |
| 169 | mutable int mScreenAcquired; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 170 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * Transaction state |
| 174 | */ |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 175 | static status_t orientationToTransfrom(int orientation, int w, int h, |
| 176 | Transform* tr); |
Mathias Agopian | 98a121a | 2012-07-24 21:08:59 -0700 | [diff] [blame] | 177 | Transform mGlobalTransform; |
| 178 | int mOrientation; |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 179 | uint32_t mLayerStack; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | }; // namespace android |
| 183 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 184 | #endif // ANDROID_DISPLAY_DEVICE_H |