blob: 58ec6dce2a5a624b05a98e24197e5cf72b43e791 [file] [log] [blame]
Mathias Agopiane3c697f2013-02-14 17:11:02 -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
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
Svetoslavd85084b2014-03-20 10:28:31 -070027#include <ui/FrameStats.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080028#include <ui/PixelFormat.h>
29#include <ui/Region.h>
30
Mathias Agopiane3c697f2013-02-14 17:11:02 -080031#include <gui/ISurfaceComposerClient.h>
32
33namespace android {
34
35// ---------------------------------------------------------------------------
36
37class IGraphicBufferProducer;
38class Surface;
39class SurfaceComposerClient;
40
41// ---------------------------------------------------------------------------
42
43class SurfaceControl : public RefBase
44{
45public:
46 static bool isValid(const sp<SurfaceControl>& surface) {
47 return (surface != 0) && surface->isValid();
48 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -070049
Mathias Agopiane3c697f2013-02-14 17:11:02 -080050 bool isValid() {
Mathias Agopian4d9b8222013-03-12 17:11:48 -070051 return mHandle!=0 && mClient!=0;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080052 }
Mathias Agopian4d9b8222013-03-12 17:11:48 -070053
Mathias Agopiane3c697f2013-02-14 17:11:02 -080054 static bool isSameSurface(
55 const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs);
Svetoslavd85084b2014-03-20 10:28:31 -070056
Mathias Agopiane3c697f2013-02-14 17:11:02 -080057 // release surface data from java
58 void clear();
Svetoslavd85084b2014-03-20 10:28:31 -070059
Chong Zhang1b3a9ac2016-02-29 16:47:47 -080060 // disconnect any api that's connected
61 void disconnect();
62
Dan Stozad723bd72014-11-18 10:24:03 -080063 status_t setLayerStack(uint32_t layerStack);
Robert Carrae060832016-11-28 10:51:00 -080064 status_t setLayer(int32_t layer);
Ramanan Rajeswarand6480c02013-03-21 15:49:59 +000065 status_t setPosition(float x, float y);
Mathias Agopiane3c697f2013-02-14 17:11:02 -080066 status_t setSize(uint32_t w, uint32_t h);
67 status_t hide();
68 status_t show();
69 status_t setFlags(uint32_t flags, uint32_t mask);
70 status_t setTransparentRegionHint(const Region& transparent);
71 status_t setAlpha(float alpha=1.0f);
72 status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy);
73 status_t setCrop(const Rect& crop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +000074 status_t setFinalCrop(const Rect& crop);
Mathias Agopiane3c697f2013-02-14 17:11:02 -080075
Robert Carr99e27f02016-06-16 15:18:02 -070076 // If the size changes in this transaction, all geometry updates specified
Robert Carr82364e32016-05-15 11:27:47 -070077 // in this transaction will not complete until a buffer of the new size
Robert Carr99e27f02016-06-16 15:18:02 -070078 // arrives. As some elements normally apply immediately, this enables
79 // freezing the total geometry of a surface until a resize is completed.
80 status_t setGeometryAppliesWithResize();
Robert Carr82364e32016-05-15 11:27:47 -070081
Dan Stoza7dde5992015-05-22 09:51:44 -070082 // Defers applying any changes made in this transaction until the Layer
Robert Carr0d480722017-01-10 16:42:54 -080083 // identified by handle reaches the given frameNumber. If the Layer identified
84 // by handle is removed, then we will apply this transaction regardless of
85 // what frame number has been reached.
Robert Carr1db73f62016-12-21 12:58:51 -080086 status_t deferTransactionUntil(const sp<IBinder>& handle, uint64_t frameNumber);
Robert Carr0d480722017-01-10 16:42:54 -080087
88 // A variant of deferTransactionUntil which identifies the Layer we wait for by
89 // Surface instead of Handle. Useful for clients which may not have the
90 // SurfaceControl for some of their Surfaces. Otherwise behaves identically.
91 status_t deferTransactionUntil(const sp<Surface>& barrier, uint64_t frameNumber);
92
Robert Carr1db73f62016-12-21 12:58:51 -080093 // Reparents all children of this layer to the new parent handle.
94 status_t reparentChildren(const sp<IBinder>& newParentHandle);
Dan Stoza7dde5992015-05-22 09:51:44 -070095
Robert Carr9524cb32017-02-13 11:32:32 -080096 // Detaches all child surfaces (and their children recursively)
97 // from their SurfaceControl.
98 // The child SurfaceControl's will not throw exceptions or return errors,
99 // but transactions will have no effect.
100 // The child surfaces will continue to follow their parent surfaces,
101 // and remain eligible for rendering, but their relative state will be
102 // frozen. We use this in the WindowManager, in app shutdown/relaunch
103 // scenarios, where the app would otherwise clean up its child Surfaces.
104 // Sometimes the WindowManager needs to extend their lifetime slightly
105 // in order to perform an exit animation or prevent flicker.
106 status_t detachChildren();
107
Robert Carrc3574f72016-03-24 12:19:32 -0700108 // Set an override scaling mode as documented in <system/window.h>
109 // the override scaling mode will take precedence over any client
110 // specified scaling mode. -1 will clear the override scaling mode.
111 status_t setOverrideScalingMode(int32_t overrideScalingMode);
112
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800113 static status_t writeSurfaceToParcel(
114 const sp<SurfaceControl>& control, Parcel* parcel);
115
116 sp<Surface> getSurface() const;
Dan Stoza7dde5992015-05-22 09:51:44 -0700117 sp<IBinder> getHandle() const;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800118
Svetoslavd85084b2014-03-20 10:28:31 -0700119 status_t clearLayerFrameStats() const;
120 status_t getLayerFrameStats(FrameStats* outStats) const;
121
Robert Carr367c5682016-06-20 11:55:28 -0700122 status_t getTransformToDisplayInverse(bool* outTransformToDisplayInverse) const;
123
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800124private:
125 // can't be copied
126 SurfaceControl& operator = (SurfaceControl& rhs);
127 SurfaceControl(const SurfaceControl& rhs);
128
129 friend class SurfaceComposerClient;
130 friend class Surface;
131
132 SurfaceControl(
133 const sp<SurfaceComposerClient>& client,
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700134 const sp<IBinder>& handle,
135 const sp<IGraphicBufferProducer>& gbp);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800136
137 ~SurfaceControl();
138
139 status_t validate() const;
140 void destroy();
Svetoslavd85084b2014-03-20 10:28:31 -0700141
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800142 sp<SurfaceComposerClient> mClient;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700143 sp<IBinder> mHandle;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800144 sp<IGraphicBufferProducer> mGraphicBufferProducer;
145 mutable Mutex mLock;
146 mutable sp<Surface> mSurfaceData;
147};
148
149}; // namespace android
150
151#endif // ANDROID_GUI_SURFACE_CONTROL_H