2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_GUI_SURFACE_H
18 #define ANDROID_GUI_SURFACE_H
21 #include <sys/types.h>
23 #include <utils/KeyedVector.h>
24 #include <utils/RefBase.h>
25 #include <utils/threads.h>
27 #include <ui/PixelFormat.h>
28 #include <ui/Region.h>
30 #include <gui/SurfaceTextureClient.h>
31 #include <gui/ISurface.h>
32 #include <gui/ISurfaceComposerClient.h>
34 #define ANDROID_VIEW_SURFACE_JNI_ID "mNativeSurface"
38 // ---------------------------------------------------------------------------
40 class ISurfaceTexture;
42 class SurfaceComposerClient;
44 // ---------------------------------------------------------------------------
46 class SurfaceControl : public RefBase
49 static bool isValid(const sp<SurfaceControl>& surface) {
50 return (surface != 0) && surface->isValid();
53 return mToken>=0 && mClient!=0;
55 static bool isSameSurface(
56 const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs);
58 uint32_t getIdentity() const { return mIdentity; }
60 // release surface data from java
63 status_t setLayer(int32_t layer);
64 status_t setPosition(int32_t x, int32_t y);
65 status_t setSize(uint32_t w, uint32_t h);
67 status_t show(int32_t layer = -1);
68 status_t setFlags(uint32_t flags, uint32_t mask);
69 status_t setTransparentRegionHint(const Region& transparent);
70 status_t setAlpha(float alpha=1.0f);
71 status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy);
72 status_t setCrop(const Rect& crop);
74 static status_t writeSurfaceToParcel(
75 const sp<SurfaceControl>& control, Parcel* parcel);
77 sp<Surface> getSurface() const;
81 SurfaceControl& operator = (SurfaceControl& rhs);
82 SurfaceControl(const SurfaceControl& rhs);
84 friend class SurfaceComposerClient;
88 const sp<SurfaceComposerClient>& client,
89 const sp<ISurface>& surface,
90 const ISurfaceComposerClient::surface_data_t& data);
94 status_t validate() const;
97 sp<SurfaceComposerClient> mClient;
98 sp<ISurface> mSurface;
103 mutable sp<Surface> mSurfaceData;
106 // ---------------------------------------------------------------------------
108 class Surface : public SurfaceTextureClient
118 uint32_t reserved[2];
121 explicit Surface(const sp<ISurfaceTexture>& st);
123 static status_t writeToParcel(const sp<Surface>& control, Parcel* parcel);
125 static sp<Surface> readFromParcel(const Parcel& data);
126 static bool isValid(const sp<Surface>& surface) {
127 return (surface != 0) && surface->isValid();
131 uint32_t getIdentity() const { return mIdentity; }
132 sp<ISurfaceTexture> getSurfaceTexture();
134 // the lock/unlock APIs must be used from the same thread
135 status_t lock(SurfaceInfo* info, Region* dirty = NULL);
136 status_t unlockAndPost();
138 sp<IBinder> asBinder() const;
141 // this is just to be able to write some unit tests
143 friend class SurfaceControl;
146 Surface& operator = (Surface& rhs);
147 Surface(const Surface& rhs);
149 explicit Surface(const sp<SurfaceControl>& control);
150 Surface(const Parcel& data, const sp<IBinder>& ref);
156 void init(const sp<ISurfaceTexture>& surfaceTexture);
158 static void cleanCachedSurfacesLocked();
160 virtual int query(int what, int* value) const;
163 sp<ISurface> mSurface;
166 // A cache of Surface objects that have been deserialized into this process.
167 static Mutex sCachedSurfacesLock;
168 static DefaultKeyedVector<wp<IBinder>, wp<Surface> > sCachedSurfaces;
171 }; // namespace android
173 #endif // ANDROID_GUI_SURFACE_H