blob: 8122b9dc5efb3ff8e7b302538c71ba8ba3cbba2c [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 Agopianf4358632012-08-22 17:16:19 -070031#include <hardware/hwcomposer_defs.h>
32
Mathias Agopian1b031492012-06-20 17:51:20 -070033#include "Transform.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070034
Mathias Agopiand8552d72012-08-04 21:39:11 -070035struct ANativeWindow;
36
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037namespace android {
38
Mathias Agopianc666cae2012-07-25 18:56:13 -070039class DisplayInfo;
Mathias Agopian3e876012012-06-07 17:52:54 -070040class FramebufferSurface;
Mathias Agopian86303202012-07-24 22:46:10 -070041class LayerBase;
42class SurfaceFlinger;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043
Mathias Agopian028a7572012-08-05 01:23:51 -070044class DisplayDevice : public LightRefBase<DisplayDevice>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045{
46public:
Mathias Agopian87baae12012-07-31 12:38:26 -070047 // region in layer-stack space
48 mutable Region dirtyRegion;
49 // region in screen space
50 mutable Region swapRegion;
51 // region in screen space
52 Region undefinedRegion;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070053
Mathias Agopian3ee454a2012-08-27 16:28:24 -070054 enum DisplayType {
55 DISPLAY_ID_INVALID = -1,
56 DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY,
57 DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL,
58 NUM_DISPLAY_TYPES = HWC_NUM_DISPLAY_TYPES,
59 DISPLAY_VIRTUAL = HWC_NUM_DISPLAY_TYPES
Mathias Agopian92a979a2012-08-02 18:32:23 -070060 };
61
62 enum {
Mathias Agopian87baae12012-07-31 12:38:26 -070063 PARTIAL_UPDATES = 0x00020000, // video driver feature
64 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065 };
66
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070067 DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068 const sp<SurfaceFlinger>& flinger,
Mathias Agopian3ee454a2012-08-27 16:28:24 -070069 DisplayType type, const wp<IBinder>& displayToken,
Jamie Gennis1a4d8832012-08-02 20:11:05 -070070 const sp<ANativeWindow>& nativeWindow,
71 const sp<FramebufferSurface>& framebufferSurface,
Mathias Agopiana4912602012-07-12 14:25:33 -070072 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080073
Mathias Agopian028a7572012-08-05 01:23:51 -070074 ~DisplayDevice();
Mathias Agopian92a979a2012-08-02 18:32:23 -070075
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 Projectedbf3b62009-03-03 19:31:44 -080080 // 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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084 int getWidth() const;
85 int getHeight() const;
86 PixelFormat getFormat() const;
87 uint32_t getFlags() const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070088
Mathias Agopiana4912602012-07-12 14:25:33 -070089 EGLSurface getEGLSurface() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070090
91 void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
Mathias Agopian3ee454a2012-08-27 16:28:24 -070092 const Vector< sp<LayerBase> >& getVisibleLayersSortedByZ() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070093 bool getSecureLayerVisible() const;
Mathias Agopiancd60f992012-08-16 16:28:27 -070094 Region getDirtyRegion(bool repaintEverything) const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070095
Mathias Agopian28947d72012-08-08 18:51:15 -070096 void setLayerStack(uint32_t stack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -070097 void setProjection(int orientation, const Rect& viewport, const Rect& frame);
Mathias Agopian28947d72012-08-08 18:51:15 -070098
Mathias Agopian1b031492012-06-20 17:51:20 -070099 int getOrientation() const { return mOrientation; }
100 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700101 const Rect& getViewport() const { return mViewport; }
102 const Rect& getFrame() const { return mFrame; }
103
Mathias Agopian87baae12012-07-31 12:38:26 -0700104 uint32_t getLayerStack() const { return mLayerStack; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700105 int32_t getDisplayType() const { return mType; }
Mathias Agopiane60b0682012-08-21 23:34:09 -0700106 int32_t getHwcDisplayId() const { return mHwcDisplayId; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700107 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700108
Mathias Agopian74faca22009-09-17 16:18:16 -0700109 status_t compositionComplete() const;
110
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700111 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700112 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800113 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700114 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800115
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700116 static EGLBoolean makeCurrent(EGLDisplay dpy,
117 const sp<const DisplayDevice>& hw, EGLContext ctx);
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700118
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700119 /* ------------------------------------------------------------------------
120 * blank / unplank management
121 */
122 void releaseScreen() const;
123 void acquireScreen() const;
124 bool isScreenAcquired() const;
125 bool canDraw() const;
126
127 /* ------------------------------------------------------------------------
128 * Debugging
129 */
130 uint32_t getPageFlipCount() const;
131 void dump(String8& res) const;
132
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700134 void init(EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135
Mathias Agopiana4912602012-07-12 14:25:33 -0700136 /*
137 * Constants, set during initialization
138 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700139 sp<SurfaceFlinger> mFlinger;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700140 DisplayType mType;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700141 int32_t mHwcDisplayId;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700142 wp<IBinder> mDisplayToken;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700143
Mathias Agopiana4912602012-07-12 14:25:33 -0700144 // ANativeWindow this display is rendering into
Mathias Agopiand8552d72012-08-04 21:39:11 -0700145 sp<ANativeWindow> mNativeWindow;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700146
Mathias Agopiana4912602012-07-12 14:25:33 -0700147 // set if mNativeWindow is a FramebufferSurface
148 sp<FramebufferSurface> mFramebufferSurface;
149
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800150 EGLDisplay mDisplay;
151 EGLSurface mSurface;
152 EGLContext mContext;
Mathias Agopian1b031492012-06-20 17:51:20 -0700153 int mDisplayWidth;
154 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800155 PixelFormat mFormat;
156 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700157 mutable uint32_t mPageFlipCount;
Mathias Agopian03e40722012-04-26 16:11:59 -0700158
Mathias Agopiana4912602012-07-12 14:25:33 -0700159 /*
160 * Can only accessed from the main thread, these members
161 * don't need synchronization.
162 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700163
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700164 // list of visible layers on that display
165 Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700166
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700167 // Whether we have a visible secure layer on this display
168 bool mSecureLayerVisible;
169
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700170 // Whether the screen is blanked;
171 mutable int mScreenAcquired;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700172
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700173
174 /*
175 * Transaction state
176 */
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700177 static status_t orientationToTransfrom(int orientation,
178 int w, int h, Transform* tr);
179
180 void updateGeometryTransform();
181
Mathias Agopian87baae12012-07-31 12:38:26 -0700182 uint32_t mLayerStack;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700183 int mOrientation;
184 Rect mViewport;
185 Rect mFrame;
186 Transform mGlobalTransform;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800187};
188
189}; // namespace android
190
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700191#endif // ANDROID_DISPLAY_DEVICE_H