1/*
2 * Copyright (C) 2012 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_SF_CLIENT_H
18#define ANDROID_SF_CLIENT_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/Errors.h>
24#include <utils/KeyedVector.h>
25#include <utils/Mutex.h>
26
27#include <gui/ISurfaceComposerClient.h>
28
29namespace android {
30
31// ---------------------------------------------------------------------------
32
33class Layer;
34class SurfaceFlinger;
35
36// ---------------------------------------------------------------------------
37
38class Client : public BnSurfaceComposerClient
39{
40public:
41        Client(const sp<SurfaceFlinger>& flinger);
42        ~Client();
43
44    status_t initCheck() const;
45
46    // protected by SurfaceFlinger::mStateLock
47    void attachLayer(const sp<IBinder>& handle, const sp<Layer>& layer);
48
49    void detachLayer(const Layer* layer);
50
51    sp<Layer> getLayerUser(const sp<IBinder>& handle) const;
52
53private:
54    // ISurfaceComposerClient interface
55    virtual status_t createSurface(
56            const String8& name,
57            uint32_t w, uint32_t h,PixelFormat format, uint32_t flags,
58            sp<IBinder>* handle,
59            sp<IGraphicBufferProducer>* gbp);
60
61    virtual status_t destroySurface(const sp<IBinder>& handle);
62
63    virtual status_t clearLayerFrameStats(const sp<IBinder>& handle) const;
64
65    virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const;
66
67    virtual status_t onTransact(
68        uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
69
70    // constant
71    sp<SurfaceFlinger> mFlinger;
72
73    // protected by mLock
74    DefaultKeyedVector< wp<IBinder>, wp<Layer> > mLayers;
75
76    // thread-safe
77    mutable Mutex mLock;
78};
79
80// ---------------------------------------------------------------------------
81}; // namespace android
82
83#endif // ANDROID_SF_CLIENT_H
84