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