blob: 993a92f9304653810e32e9b63f3fd8d193817420 [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
Dan Stozad723bd72014-11-18 10:24:03 -080060 status_t setLayerStack(uint32_t layerStack);
61 status_t setLayer(uint32_t layer);
Ramanan Rajeswarand6480c02013-03-21 15:49:59 +000062 status_t setPosition(float x, float y);
Mathias Agopiane3c697f2013-02-14 17:11:02 -080063 status_t setSize(uint32_t w, uint32_t h);
64 status_t hide();
65 status_t show();
66 status_t setFlags(uint32_t flags, uint32_t mask);
67 status_t setTransparentRegionHint(const Region& transparent);
68 status_t setAlpha(float alpha=1.0f);
69 status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy);
70 status_t setCrop(const Rect& crop);
71
Dan Stoza7dde5992015-05-22 09:51:44 -070072 // Defers applying any changes made in this transaction until the Layer
73 // identified by handle reaches the given frameNumber
74 status_t deferTransactionUntil(sp<IBinder> handle, uint64_t frameNumber);
75
Mathias Agopiane3c697f2013-02-14 17:11:02 -080076 static status_t writeSurfaceToParcel(
77 const sp<SurfaceControl>& control, Parcel* parcel);
78
79 sp<Surface> getSurface() const;
Dan Stoza7dde5992015-05-22 09:51:44 -070080 sp<IBinder> getHandle() const;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080081
Svetoslavd85084b2014-03-20 10:28:31 -070082 status_t clearLayerFrameStats() const;
83 status_t getLayerFrameStats(FrameStats* outStats) const;
84
Mathias Agopiane3c697f2013-02-14 17:11:02 -080085private:
86 // can't be copied
87 SurfaceControl& operator = (SurfaceControl& rhs);
88 SurfaceControl(const SurfaceControl& rhs);
89
90 friend class SurfaceComposerClient;
91 friend class Surface;
92
93 SurfaceControl(
94 const sp<SurfaceComposerClient>& client,
Mathias Agopian4d9b8222013-03-12 17:11:48 -070095 const sp<IBinder>& handle,
96 const sp<IGraphicBufferProducer>& gbp);
Mathias Agopiane3c697f2013-02-14 17:11:02 -080097
98 ~SurfaceControl();
99
100 status_t validate() const;
101 void destroy();
Svetoslavd85084b2014-03-20 10:28:31 -0700102
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800103 sp<SurfaceComposerClient> mClient;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700104 sp<IBinder> mHandle;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800105 sp<IGraphicBufferProducer> mGraphicBufferProducer;
106 mutable Mutex mLock;
107 mutable sp<Surface> mSurfaceData;
108};
109
110}; // namespace android
111
112#endif // ANDROID_GUI_SURFACE_CONTROL_H