blob: 0a75bf3138258a879804ae319dd5ce0703ff80a1 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
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_UI_SURFACE_H
18#define ANDROID_UI_SURFACE_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/RefBase.h>
24#include <utils/threads.h>
25
26#include <ui/ISurface.h>
27#include <ui/PixelFormat.h>
28#include <ui/Region.h>
29#include <ui/ISurfaceFlingerClient.h>
30
31namespace android {
32
33// ---------------------------------------------------------------------------
34
35class Rect;
36class SurfaceComposerClient;
37
38class Surface : public RefBase
39{
40
41public:
42 struct SurfaceInfo {
43 uint32_t w;
44 uint32_t h;
45 uint32_t bpr;
46 PixelFormat format;
47 void* bits;
48 void* base;
49 uint32_t reserved[2];
50 };
51
52 bool isValid() const { return this && mToken>=0 && mClient!=0; }
53 SurfaceID ID() const { return mToken; }
54
55 status_t lock(SurfaceInfo* info, bool blocking = true);
56 status_t lock(SurfaceInfo* info, Region* dirty, bool blocking = true);
57 status_t unlockAndPost();
58 status_t unlock();
59
60 void* heapBase(int i) const;
61 uint32_t getFlags() const { return mFlags; }
62 int getMemoryType() const { return mMemoryType; }
63
64 // setSwapRectangle() is mainly used by EGL
65 void setSwapRectangle(const Rect& r);
66 const Rect& swapRectangle() const;
67 status_t nextBuffer(SurfaceInfo* info);
68
69 sp<Surface> dup() const;
70 static sp<Surface> readFromParcel(Parcel* parcel);
71 static status_t writeToParcel(const sp<Surface>& surface, Parcel* parcel);
72 static bool isSameSurface(const sp<Surface>& lhs, const sp<Surface>& rhs);
73
74 status_t setLayer(int32_t layer);
75 status_t setPosition(int32_t x, int32_t y);
76 status_t setSize(uint32_t w, uint32_t h);
77 status_t hide();
78 status_t show(int32_t layer = -1);
79 status_t freeze();
80 status_t unfreeze();
81 status_t setFlags(uint32_t flags, uint32_t mask);
82 status_t setTransparentRegionHint(const Region& transparent);
83 status_t setAlpha(float alpha=1.0f);
84 status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy);
85 status_t setFreezeTint(uint32_t tint);
86
87 uint32_t getIdentity() const { return mIdentity; }
88private:
89 friend class SurfaceComposerClient;
90
91 // camera needs access to the ISurface binder interface for preview
92 friend class Camera;
93 // mediaplayer needs access to ISurface for display
94 friend class MediaPlayer;
95 const sp<ISurface>& getISurface() const { return mSurface; }
96
97 // can't be copied
98 Surface& operator = (Surface& rhs);
99 Surface(const Surface& rhs);
100
101 Surface(const sp<SurfaceComposerClient>& client,
102 const sp<ISurface>& surface,
103 const ISurfaceFlingerClient::surface_data_t& data,
104 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags,
105 bool owner = true);
106
107 Surface(Surface const* rhs);
108
109 ~Surface();
110
111 Region dirtyRegion() const;
112 void setDirtyRegion(const Region& region) const;
113
114 // this locks protects calls to lockSurface() / unlockSurface()
115 // and is called by SurfaceComposerClient.
116 Mutex& getLock() const { return mSurfaceLock; }
117
118 sp<SurfaceComposerClient> mClient;
119 sp<ISurface> mSurface;
120 sp<IMemoryHeap> mHeap[2];
121 int mMemoryType;
122 SurfaceID mToken;
123 uint32_t mIdentity;
124 PixelFormat mFormat;
125 uint32_t mFlags;
126 const bool mOwner;
127 mutable void* mSurfaceHeapBase[2];
128 mutable Region mDirtyRegion;
129 mutable Rect mSwapRectangle;
130 mutable uint8_t mBackbufferIndex;
131 mutable Mutex mSurfaceLock;
132};
133
134}; // namespace android
135
136#endif // ANDROID_UI_SURFACE_H
137