Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -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 | |
| 17 | #ifndef ANDROID_GUI_SURFACE_CONTROL_H |
| 18 | #define ANDROID_GUI_SURFACE_CONTROL_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/KeyedVector.h> |
| 24 | #include <utils/RefBase.h> |
| 25 | #include <utils/threads.h> |
| 26 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 27 | #include <ui/FrameStats.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 28 | #include <ui/PixelFormat.h> |
| 29 | #include <ui/Region.h> |
| 30 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 31 | #include <gui/ISurfaceComposerClient.h> |
| 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | // --------------------------------------------------------------------------- |
| 36 | |
| 37 | class IGraphicBufferProducer; |
| 38 | class Surface; |
| 39 | class SurfaceComposerClient; |
| 40 | |
| 41 | // --------------------------------------------------------------------------- |
| 42 | |
| 43 | class SurfaceControl : public RefBase |
| 44 | { |
| 45 | public: |
| 46 | static bool isValid(const sp<SurfaceControl>& surface) { |
| 47 | return (surface != 0) && surface->isValid(); |
| 48 | } |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 49 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 50 | bool isValid() { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 51 | return mHandle!=0 && mClient!=0; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 52 | } |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 53 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 54 | static bool isSameSurface( |
| 55 | const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs); |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 56 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 57 | // release surface data from java |
| 58 | void clear(); |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 59 | |
Chong Zhang | 1b3a9ac | 2016-02-29 16:47:47 -0800 | [diff] [blame] | 60 | // disconnect any api that's connected |
| 61 | void disconnect(); |
| 62 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 63 | status_t setLayerStack(uint32_t layerStack); |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 64 | status_t setLayer(int32_t layer); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 65 | |
| 66 | // Sets a Z order relative to the Surface specified by "relativeTo" but |
| 67 | // without becoming a full child of the relative. Z-ordering works exactly |
| 68 | // as if it were a child however. |
| 69 | // |
| 70 | // As a nod to sanity, only non-child surfaces may have a relative Z-order. |
| 71 | // |
| 72 | // This overrides any previous and is overriden by any future calls |
| 73 | // to setLayer. |
| 74 | // |
| 75 | // If the relative dissapears, the Surface will have no layer and be |
| 76 | // invisible, until the next time set(Relative)Layer is called. |
| 77 | // |
| 78 | // TODO: This is probably a hack. Currently it exists only to work around |
| 79 | // some framework usage of the hidden APPLICATION_MEDIA_OVERLAY window type |
| 80 | // which allows inserting a window between a SurfaceView and it's main application |
| 81 | // window. However, since we are using child windows for the SurfaceView, but not using |
| 82 | // child windows elsewhere in O, the WindowManager can't set the layer appropriately. |
| 83 | // This is only used by the "TvInputService" and following the port of ViewRootImpl |
| 84 | // to child surfaces, we can then port this and remove this method. |
| 85 | status_t setRelativeLayer(const sp<IBinder>& relativeTo, int32_t layer); |
Ramanan Rajeswaran | d6480c0 | 2013-03-21 15:49:59 +0000 | [diff] [blame] | 86 | status_t setPosition(float x, float y); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 87 | status_t setSize(uint32_t w, uint32_t h); |
| 88 | status_t hide(); |
| 89 | status_t show(); |
| 90 | status_t setFlags(uint32_t flags, uint32_t mask); |
| 91 | status_t setTransparentRegionHint(const Region& transparent); |
| 92 | status_t setAlpha(float alpha=1.0f); |
Robert Carr | cb6e1e3 | 2017-02-21 19:48:26 -0800 | [diff] [blame] | 93 | status_t setMatrix(float dsdx, float dtdx, float dtdy, float dsdy); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 94 | status_t setCrop(const Rect& crop); |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 95 | status_t setFinalCrop(const Rect& crop); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 96 | |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 97 | // If the size changes in this transaction, all geometry updates specified |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 98 | // in this transaction will not complete until a buffer of the new size |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 99 | // arrives. As some elements normally apply immediately, this enables |
| 100 | // freezing the total geometry of a surface until a resize is completed. |
| 101 | status_t setGeometryAppliesWithResize(); |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 102 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 103 | // Defers applying any changes made in this transaction until the Layer |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 104 | // identified by handle reaches the given frameNumber. If the Layer identified |
| 105 | // by handle is removed, then we will apply this transaction regardless of |
| 106 | // what frame number has been reached. |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 107 | status_t deferTransactionUntil(const sp<IBinder>& handle, uint64_t frameNumber); |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 108 | |
| 109 | // A variant of deferTransactionUntil which identifies the Layer we wait for by |
| 110 | // Surface instead of Handle. Useful for clients which may not have the |
| 111 | // SurfaceControl for some of their Surfaces. Otherwise behaves identically. |
| 112 | status_t deferTransactionUntil(const sp<Surface>& barrier, uint64_t frameNumber); |
| 113 | |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 114 | // Reparents all children of this layer to the new parent handle. |
| 115 | status_t reparentChildren(const sp<IBinder>& newParentHandle); |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 116 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 117 | // Detaches all child surfaces (and their children recursively) |
| 118 | // from their SurfaceControl. |
| 119 | // The child SurfaceControl's will not throw exceptions or return errors, |
| 120 | // but transactions will have no effect. |
| 121 | // The child surfaces will continue to follow their parent surfaces, |
| 122 | // and remain eligible for rendering, but their relative state will be |
| 123 | // frozen. We use this in the WindowManager, in app shutdown/relaunch |
| 124 | // scenarios, where the app would otherwise clean up its child Surfaces. |
| 125 | // Sometimes the WindowManager needs to extend their lifetime slightly |
| 126 | // in order to perform an exit animation or prevent flicker. |
| 127 | status_t detachChildren(); |
| 128 | |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 129 | // Set an override scaling mode as documented in <system/window.h> |
| 130 | // the override scaling mode will take precedence over any client |
| 131 | // specified scaling mode. -1 will clear the override scaling mode. |
| 132 | status_t setOverrideScalingMode(int32_t overrideScalingMode); |
| 133 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 134 | static status_t writeSurfaceToParcel( |
| 135 | const sp<SurfaceControl>& control, Parcel* parcel); |
| 136 | |
| 137 | sp<Surface> getSurface() const; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 138 | sp<IBinder> getHandle() const; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 139 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 140 | status_t clearLayerFrameStats() const; |
| 141 | status_t getLayerFrameStats(FrameStats* outStats) const; |
| 142 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 143 | private: |
| 144 | // can't be copied |
| 145 | SurfaceControl& operator = (SurfaceControl& rhs); |
| 146 | SurfaceControl(const SurfaceControl& rhs); |
| 147 | |
| 148 | friend class SurfaceComposerClient; |
| 149 | friend class Surface; |
| 150 | |
| 151 | SurfaceControl( |
| 152 | const sp<SurfaceComposerClient>& client, |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 153 | const sp<IBinder>& handle, |
| 154 | const sp<IGraphicBufferProducer>& gbp); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 155 | |
| 156 | ~SurfaceControl(); |
| 157 | |
| 158 | status_t validate() const; |
| 159 | void destroy(); |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 160 | |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 161 | sp<SurfaceComposerClient> mClient; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 162 | sp<IBinder> mHandle; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 163 | sp<IGraphicBufferProducer> mGraphicBufferProducer; |
| 164 | mutable Mutex mLock; |
| 165 | mutable sp<Surface> mSurfaceData; |
| 166 | }; |
| 167 | |
| 168 | }; // namespace android |
| 169 | |
| 170 | #endif // ANDROID_GUI_SURFACE_CONTROL_H |