blob: d7aa6fb6818063c31e40038a45b993a91aa69fdc [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 Agopiand3ee2312012-08-02 14:01:42 -070017#ifndef ANDROID_DISPLAY_DEVICE_H
18#define ANDROID_DISPLAY_DEVICE_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019
20#include <stdlib.h>
21
22#include <ui/PixelFormat.h>
23#include <ui/Region.h>
24
25#include <EGL/egl.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070026#include <EGL/eglext.h>
27
Mathias Agopian86303202012-07-24 22:46:10 -070028#include <utils/Mutex.h>
29#include <utils/Timers.h>
30
Mathias Agopian1b031492012-06-20 17:51:20 -070031#include "Transform.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070032
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033namespace android {
34
Mathias Agopianc666cae2012-07-25 18:56:13 -070035class DisplayInfo;
Mathias Agopian3e876012012-06-07 17:52:54 -070036class FramebufferSurface;
Mathias Agopian86303202012-07-24 22:46:10 -070037class LayerBase;
38class SurfaceFlinger;
Mathias Agopiana4912602012-07-12 14:25:33 -070039class SurfaceTextureClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040
Mathias Agopiand3ee2312012-08-02 14:01:42 -070041class DisplayDevice
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042{
43public:
Mathias Agopian87baae12012-07-31 12:38:26 -070044 // 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;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070050
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051 enum {
Mathias Agopian92a979a2012-08-02 18:32:23 -070052 DISPLAY_ID_MAIN = 0,
53 DISPLAY_ID_HDMI = 1
54 };
55
56 enum {
Mathias Agopian87baae12012-07-31 12:38:26 -070057 PARTIAL_UPDATES = 0x00020000, // video driver feature
58 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059 };
60
Mathias Agopian92a979a2012-08-02 18:32:23 -070061 DisplayDevice();
62
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070063 DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064 const sp<SurfaceFlinger>& flinger,
Mathias Agopiana4912602012-07-12 14:25:33 -070065 int dpy,
66 const sp<SurfaceTextureClient>& surface,
67 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068
Mathias Agopiand3ee2312012-08-02 14:01:42 -070069 ~DisplayDevice();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070
Mathias Agopian92a979a2012-08-02 18:32:23 -070071 // must be called when this object is no longer needed. this will
72 // render the associated EGLSurface invalid.
73 void terminate();
74
75 // whether this is a valid object. An invalid DisplayDevice is returned
76 // when an non existing id is requested
77 bool isValid() const;
78
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079 // Flip the front and back buffers if the back buffer is "dirty". Might
80 // be instantaneous, might involve copying the frame buffer around.
81 void flip(const Region& dirty) const;
82
83 float getDpiX() const;
84 float getDpiY() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085 float getDensity() const;
86 int getWidth() const;
87 int getHeight() const;
88 PixelFormat getFormat() const;
89 uint32_t getFlags() const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070090
Mathias Agopiana4912602012-07-12 14:25:33 -070091 EGLSurface getEGLSurface() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070092
93 void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
94 Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const;
95 bool getSecureLayerVisible() const;
96
Mathias Agopian1b031492012-06-20 17:51:20 -070097 status_t setOrientation(int orientation);
98 int getOrientation() const { return mOrientation; }
99 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700100 uint32_t getLayerStack() const { return mLayerStack; }
101
Mathias Agopian74faca22009-09-17 16:18:16 -0700102 status_t compositionComplete() const;
103
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700104 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700105 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700107 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800108
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700109 static void makeCurrent(const DisplayDevice& hw, EGLContext ctx);
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700110
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700111 /* ------------------------------------------------------------------------
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 Agopian92a979a2012-08-02 18:32:23 -0700125 inline bool operator < (const DisplayDevice& rhs) const {
126 return mId < rhs.mId;
127 }
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700128
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800129private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700130 void init(EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800131
Mathias Agopiana4912602012-07-12 14:25:33 -0700132 /*
133 * Constants, set during initialization
134 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700135 sp<SurfaceFlinger> mFlinger;
Mathias Agopian92a979a2012-08-02 18:32:23 -0700136 int32_t mId;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700137
Mathias Agopiana4912602012-07-12 14:25:33 -0700138 // ANativeWindow this display is rendering into
139 sp<SurfaceTextureClient> mNativeWindow;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700140
Mathias Agopiana4912602012-07-12 14:25:33 -0700141 // set if mNativeWindow is a FramebufferSurface
142 sp<FramebufferSurface> mFramebufferSurface;
143
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800144 EGLDisplay mDisplay;
145 EGLSurface mSurface;
146 EGLContext mContext;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800147 float mDpiX;
148 float mDpiY;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800149 float mDensity;
Mathias Agopian1b031492012-06-20 17:51:20 -0700150 int mDisplayWidth;
151 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800152 PixelFormat mFormat;
153 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700154 mutable uint32_t mPageFlipCount;
Mathias Agopian03e40722012-04-26 16:11:59 -0700155
Mathias Agopiana4912602012-07-12 14:25:33 -0700156 /*
157 * Can only accessed from the main thread, these members
158 * don't need synchronization.
159 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700160
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700161 // list of visible layers on that display
162 Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700163
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700164 // Whether we have a visible secure layer on this display
165 bool mSecureLayerVisible;
166
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700167 // Whether the screen is blanked;
168 mutable int mScreenAcquired;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700169
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700170
171 /*
172 * Transaction state
173 */
Mathias Agopian1b031492012-06-20 17:51:20 -0700174 static status_t orientationToTransfrom(int orientation, int w, int h,
175 Transform* tr);
Mathias Agopian98a121a2012-07-24 21:08:59 -0700176 Transform mGlobalTransform;
177 int mOrientation;
Mathias Agopian87baae12012-07-31 12:38:26 -0700178 uint32_t mLayerStack;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800179};
180
181}; // namespace android
182
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700183#endif // ANDROID_DISPLAY_DEVICE_H