blob: 99affdae64d00cb2e148703c911e2e299fa58c9c [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 Agopian9cce3252010-02-09 17:46:37 -080017#ifndef ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
18#define ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019
20#include <stdint.h>
21#include <sys/types.h>
22
Mathias Agopiandd3423c2009-09-23 15:44:05 -070023#include <binder/IBinder.h>
24
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025#include <utils/RefBase.h>
Mathias Agopianb7e930d2010-06-01 15:12:58 -070026#include <utils/Singleton.h>
27#include <utils/SortedVector.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028#include <utils/threads.h>
29
30#include <ui/PixelFormat.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080031
32#include <surfaceflinger/Surface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
34namespace android {
35
36// ---------------------------------------------------------------------------
37
Mathias Agopian9cce3252010-02-09 17:46:37 -080038class DisplayInfo;
Mathias Agopian698c0872011-06-28 19:09:31 -070039class Composer;
Mathias Agopiana67932f2011-04-20 14:20:59 -070040class IMemoryHeap;
Mathias Agopian41f673c2011-11-17 17:48:35 -080041class ISurfaceComposerClient;
Mathias Agopiana67932f2011-04-20 14:20:59 -070042class Region;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070043
44// ---------------------------------------------------------------------------
45
Mathias Agopiand4784a32010-05-27 19:41:15 -070046class SurfaceComposerClient : public RefBase
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047{
Mathias Agopian698c0872011-06-28 19:09:31 -070048 friend class Composer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049public:
50 SurfaceComposerClient();
51 virtual ~SurfaceComposerClient();
52
53 // Always make sure we could initialize
54 status_t initCheck() const;
55
56 // Return the connection of this client
57 sp<IBinder> connection() const;
58
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059 // Forcibly remove connection before all references have gone away.
60 void dispose();
61
62 // ------------------------------------------------------------------------
63 // surface creation / destruction
64
65 //! Create a surface
Mathias Agopian01b76682009-04-16 20:04:08 -070066 sp<SurfaceControl> createSurface(
Mathias Agopian285dbde2010-03-01 16:09:43 -080067 const String8& name,// name of the surface
Mathias Agopiancbb288b2009-09-07 16:32:45 -070068 DisplayID display, // Display to create this surface on
69 uint32_t w, // width in pixel
70 uint32_t h, // height in pixel
71 PixelFormat format, // pixel-format desired
72 uint32_t flags = 0 // usage flags
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080073 );
74
Mathias Agopian285dbde2010-03-01 16:09:43 -080075 sp<SurfaceControl> createSurface(
Mathias Agopian285dbde2010-03-01 16:09:43 -080076 DisplayID display, // Display to create this surface on
77 uint32_t w, // width in pixel
78 uint32_t h, // height in pixel
79 PixelFormat format, // pixel-format desired
80 uint32_t flags = 0 // usage flags
81 );
82
83
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084 // ------------------------------------------------------------------------
85 // Composer parameters
86 // All composer parameters must be changed within a transaction
87 // several surfaces can be updated in one transaction, all changes are
88 // committed at once when the transaction is closed.
Mathias Agopian698c0872011-06-28 19:09:31 -070089 // closeGlobalTransaction() usually requires an IPC with the server.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090
91 //! Open a composer transaction on all active SurfaceComposerClients.
92 static void openGlobalTransaction();
93
94 //! Close a composer transaction on all active SurfaceComposerClients.
Jamie Gennis28378392011-10-12 17:39:00 -070095 static void closeGlobalTransaction(bool synchronous = false);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096
97 //! Freeze the specified display but not transactions.
98 static status_t freezeDisplay(DisplayID dpy, uint32_t flags = 0);
99
100 //! Resume updates on the specified display.
101 static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0);
102
103 //! Set the orientation of the given display
Mathias Agopianc08731e2009-03-27 18:11:38 -0700104 static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105
106 // Query the number of displays
107 static ssize_t getNumberOfDisplays();
108
109 // Get information about a display
110 static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
111 static ssize_t getDisplayWidth(DisplayID dpy);
112 static ssize_t getDisplayHeight(DisplayID dpy);
113 static ssize_t getDisplayOrientation(DisplayID dpy);
114
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700115 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
116 void* cookie = NULL, uint32_t flags = 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800117
Mathias Agopian62185b72009-04-16 16:19:50 -0700118 status_t hide(SurfaceID id);
119 status_t show(SurfaceID id, int32_t layer = -1);
120 status_t freeze(SurfaceID id);
121 status_t unfreeze(SurfaceID id);
122 status_t setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
123 status_t setTransparentRegionHint(SurfaceID id, const Region& transparent);
124 status_t setLayer(SurfaceID id, int32_t layer);
125 status_t setAlpha(SurfaceID id, float alpha=1.0f);
126 status_t setFreezeTint(SurfaceID id, uint32_t tint);
127 status_t setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700128 status_t setPosition(SurfaceID id, float x, float y);
Mathias Agopian62185b72009-04-16 16:19:50 -0700129 status_t setSize(SurfaceID id, uint32_t w, uint32_t h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130 status_t destroySurface(SurfaceID sid);
131
Mathias Agopian631f3582010-05-25 17:51:34 -0700132private:
Mathias Agopiand4784a32010-05-27 19:41:15 -0700133 virtual void onFirstRef();
Mathias Agopian698c0872011-06-28 19:09:31 -0700134 Composer& getComposer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135
Mathias Agopian698c0872011-06-28 19:09:31 -0700136 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800137 status_t mStatus;
Mathias Agopian7e27f052010-05-28 14:22:23 -0700138 sp<ISurfaceComposerClient> mClient;
Mathias Agopian698c0872011-06-28 19:09:31 -0700139 Composer& mComposer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800140};
141
Mathias Agopiand4784a32010-05-27 19:41:15 -0700142// ---------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700143
144class ScreenshotClient
145{
146 sp<IMemoryHeap> mHeap;
147 uint32_t mWidth;
148 uint32_t mHeight;
149 PixelFormat mFormat;
150public:
151 ScreenshotClient();
152
153 // frees the previous screenshot and capture a new one
154 status_t update();
155 status_t update(uint32_t reqWidth, uint32_t reqHeight);
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800156 status_t update(uint32_t reqWidth, uint32_t reqHeight,
157 uint32_t minLayerZ, uint32_t maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700158
159 // release memory occupied by the screenshot
160 void release();
161
162 // pixels are valid until this object is freed or
163 // release() or update() is called
164 void const* getPixels() const;
165
166 uint32_t getWidth() const;
167 uint32_t getHeight() const;
168 PixelFormat getFormat() const;
169 uint32_t getStride() const;
170 // size of allocated memory in bytes
171 size_t getSize() const;
172};
173
174// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800175}; // namespace android
176
Mathias Agopian9cce3252010-02-09 17:46:37 -0800177#endif // ANDROID_SF_SURFACE_COMPOSER_CLIENT_H