DisplayDevice.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. #ifndef ANDROID_DISPLAY_DEVICE_H
  17. #define ANDROID_DISPLAY_DEVICE_H
  18. #include <stdlib.h>
  19. #include <ui/PixelFormat.h>
  20. #include <ui/Region.h>
  21. #include <EGL/egl.h>
  22. #include <EGL/eglext.h>
  23. #include <utils/Mutex.h>
  24. #include <utils/String8.h>
  25. #include <utils/Timers.h>
  26. #include <hardware/hwcomposer_defs.h>
  27. #include "Transform.h"
  28. struct ANativeWindow;
  29. namespace android {
  30. struct DisplayInfo;
  31. class DisplaySurface;
  32. class IGraphicBufferProducer;
  33. class Layer;
  34. class SurfaceFlinger;
  35. class HWComposer;
  36. class DisplayDevice : public LightRefBase<DisplayDevice>
  37. {
  38. public:
  39. // region in layer-stack space
  40. mutable Region dirtyRegion;
  41. // region in screen space
  42. mutable Region swapRegion;
  43. // region in screen space
  44. Region undefinedRegion;
  45. bool lastCompositionHadVisibleLayers;
  46. enum DisplayType {
  47. DISPLAY_ID_INVALID = -1,
  48. DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY,
  49. DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL,
  50. DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL,
  51. NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
  52. };
  53. enum {
  54. PARTIAL_UPDATES = 0x00020000, // video driver feature
  55. SWAP_RECTANGLE = 0x00080000,
  56. };
  57. enum {
  58. NO_LAYER_STACK = 0xFFFFFFFF,
  59. };
  60. DisplayDevice(
  61. const sp<SurfaceFlinger>& flinger,
  62. DisplayType type,
  63. int32_t hwcId, // negative for non-HWC-composited displays
  64. int format,
  65. bool isSecure,
  66. const wp<IBinder>& displayToken,
  67. const sp<DisplaySurface>& displaySurface,
  68. const sp<IGraphicBufferProducer>& producer,
  69. EGLConfig config);
  70. ~DisplayDevice();
  71. // whether this is a valid object. An invalid DisplayDevice is returned
  72. // when an non existing id is requested
  73. bool isValid() const;
  74. // isSecure indicates whether this display can be trusted to display
  75. // secure surfaces.
  76. bool isSecure() const { return mIsSecure; }
  77. // Flip the front and back buffers if the back buffer is "dirty". Might
  78. // be instantaneous, might involve copying the frame buffer around.
  79. void flip(const Region& dirty) const;
  80. int getWidth() const;
  81. int getHeight() const;
  82. PixelFormat getFormat() const;
  83. uint32_t getFlags() const;
  84. EGLSurface getEGLSurface() const;
  85. void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
  86. const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
  87. bool getSecureLayerVisible() const;
  88. Region getDirtyRegion(bool repaintEverything) const;
  89. void setLayerStack(uint32_t stack);
  90. void setDisplaySize(const int newWidth, const int newHeight);
  91. void setProjection(int orientation, const Rect& viewport, const Rect& frame);
  92. int getOrientation() const { return mOrientation; }
  93. uint32_t getOrientationTransform() const;
  94. const Transform& getTransform() const { return mGlobalTransform; }
  95. const Rect getViewport() const { return mViewport; }
  96. const Rect getFrame() const { return mFrame; }
  97. const Rect& getScissor() const { return mScissor; }
  98. bool needsFiltering() const { return mNeedsFiltering; }
  99. uint32_t getLayerStack() const { return mLayerStack; }
  100. int32_t getDisplayType() const { return mType; }
  101. int32_t getHwcDisplayId() const { return mHwcDisplayId; }
  102. const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
  103. uint32_t getPanelMountFlip() const {
  104. return mPanelMountFlip;
  105. }
  106. // We pass in mustRecompose so we can keep VirtualDisplaySurface's state
  107. // machine happy without actually queueing a buffer if nothing has changed
  108. status_t beginFrame(bool mustRecompose) const;
  109. status_t prepareFrame(const HWComposer& hwc) const;
  110. void swapBuffers(HWComposer& hwc) const;
  111. status_t compositionComplete() const;
  112. // called after h/w composer has completed its set() call
  113. void onSwapBuffersCompleted(HWComposer& hwc) const;
  114. Rect getBounds() const {
  115. return Rect(mDisplayWidth, mDisplayHeight);
  116. }
  117. inline Rect bounds() const { return getBounds(); }
  118. void setDisplayName(const String8& displayName);
  119. const String8& getDisplayName() const { return mDisplayName; }
  120. EGLBoolean makeCurrent(EGLDisplay dpy, EGLContext ctx) const;
  121. void setViewportAndProjection() const;
  122. /* ------------------------------------------------------------------------
  123. * Display power mode management.
  124. */
  125. int getPowerMode() const;
  126. void setPowerMode(int mode);
  127. bool isDisplayOn() const;
  128. /* ------------------------------------------------------------------------
  129. * Display active config management.
  130. */
  131. int getActiveConfig() const;
  132. void setActiveConfig(int mode);
  133. // release HWC resources (if any) for removable displays
  134. void disconnect(HWComposer& hwc);
  135. /* ------------------------------------------------------------------------
  136. * Debugging
  137. */
  138. uint32_t getPageFlipCount() const;
  139. void dump(String8& result) const;
  140. private:
  141. /*
  142. * Constants, set during initialization
  143. */
  144. sp<SurfaceFlinger> mFlinger;
  145. DisplayType mType;
  146. int32_t mHwcDisplayId;
  147. wp<IBinder> mDisplayToken;
  148. // ANativeWindow this display is rendering into
  149. sp<ANativeWindow> mNativeWindow;
  150. sp<DisplaySurface> mDisplaySurface;
  151. EGLConfig mConfig;
  152. EGLDisplay mDisplay;
  153. EGLSurface mSurface;
  154. int mDisplayWidth;
  155. int mDisplayHeight;
  156. PixelFormat mFormat;
  157. uint32_t mFlags;
  158. mutable uint32_t mPageFlipCount;
  159. String8 mDisplayName;
  160. bool mIsSecure;
  161. /*
  162. * Can only accessed from the main thread, these members
  163. * don't need synchronization.
  164. */
  165. // list of visible layers on that display
  166. Vector< sp<Layer> > mVisibleLayersSortedByZ;
  167. // Whether we have a visible secure layer on this display
  168. bool mSecureLayerVisible;
  169. /*
  170. * Transaction state
  171. */
  172. status_t orientationToTransfrom(int orientation,
  173. int w, int h, Transform* tr);
  174. uint32_t mLayerStack;
  175. int mOrientation;
  176. // user-provided visible area of the layer stack
  177. Rect mViewport;
  178. // user-provided rectangle where mViewport gets mapped to
  179. Rect mFrame;
  180. // pre-computed scissor to apply to the display
  181. Rect mScissor;
  182. Transform mGlobalTransform;
  183. bool mNeedsFiltering;
  184. // Current power mode
  185. int mPowerMode;
  186. // Current active config
  187. int mActiveConfig;
  188. // Panel's mount flip, H, V or 180 (HV)
  189. uint32_t mPanelMountFlip;
  190. };
  191. }; // namespace android
  192. #endif // ANDROID_DISPLAY_DEVICE_H