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_UI_SURFACE_H
18 #define ANDROID_UI_SURFACE_H
21 #include <sys/types.h>
23 #include <utils/RefBase.h>
24 #include <utils/threads.h>
26 #include <ui/ISurface.h>
27 #include <ui/PixelFormat.h>
28 #include <ui/Region.h>
29 #include <ui/ISurfaceFlingerClient.h>
33 // ---------------------------------------------------------------------------
36 class SurfaceComposerClient;
38 class Surface : public RefBase
52 bool isValid() const { return this && mToken>=0 && mClient!=0; }
53 SurfaceID ID() const { return mToken; }
55 status_t lock(SurfaceInfo* info, bool blocking = true);
56 status_t lock(SurfaceInfo* info, Region* dirty, bool blocking = true);
57 status_t unlockAndPost();
60 void* heapBase(int i) const;
61 uint32_t getFlags() const { return mFlags; }
63 // setSwapRectangle() is mainly used by EGL
64 void setSwapRectangle(const Rect& r);
65 const Rect& swapRectangle() const;
66 status_t nextBuffer(SurfaceInfo* info);
68 sp<Surface> dup() const;
69 static sp<Surface> readFromParcel(Parcel* parcel);
70 static status_t writeToParcel(const sp<Surface>& surface, Parcel* parcel);
71 static bool isSameSurface(const sp<Surface>& lhs, const sp<Surface>& rhs);
73 status_t setLayer(int32_t layer);
74 status_t setPosition(int32_t x, int32_t y);
75 status_t setSize(uint32_t w, uint32_t h);
77 status_t show(int32_t layer = -1);
80 status_t setFlags(uint32_t flags, uint32_t mask);
81 status_t setTransparentRegionHint(const Region& transparent);
82 status_t setAlpha(float alpha=1.0f);
83 status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy);
84 status_t setFreezeTint(uint32_t tint);
86 uint32_t getIdentity() const { return mIdentity; }
88 friend class SurfaceComposerClient;
90 // camera and camcorder need access to the ISurface binder interface for preview
92 friend class MediaRecorder;
93 // mediaplayer needs access to ISurface for display
94 friend class MediaPlayer;
96 const sp<ISurface>& getISurface() const { return mSurface; }
99 Surface& operator = (Surface& rhs);
100 Surface(const Surface& rhs);
102 Surface(const sp<SurfaceComposerClient>& client,
103 const sp<ISurface>& surface,
104 const ISurfaceFlingerClient::surface_data_t& data,
105 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags,
108 Surface(Surface const* rhs);
112 Region dirtyRegion() const;
113 void setDirtyRegion(const Region& region) const;
115 // this locks protects calls to lockSurface() / unlockSurface()
116 // and is called by SurfaceComposerClient.
117 Mutex& getLock() const { return mSurfaceLock; }
119 sp<SurfaceComposerClient> mClient;
120 sp<ISurface> mSurface;
121 sp<IMemoryHeap> mHeap[2];
127 mutable void* mSurfaceHeapBase[2];
128 mutable Region mDirtyRegion;
129 mutable Rect mSwapRectangle;
130 mutable uint8_t mBackbufferIndex;
131 mutable Mutex mSurfaceLock;
134 }; // namespace android
136 #endif // ANDROID_UI_SURFACE_H