1/*
2 * Copyright (C) 2015-2018 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_HARDWARE_CAMERA2_OUTPUTCONFIGURATION_H
18#define ANDROID_HARDWARE_CAMERA2_OUTPUTCONFIGURATION_H
19
20#include <gui/IGraphicBufferProducer.h>
21#include <binder/Parcelable.h>
22
23namespace android {
24
25class Surface;
26
27namespace hardware {
28namespace camera2 {
29namespace params {
30
31class OutputConfiguration : public android::Parcelable {
32public:
33
34    static const int INVALID_ROTATION;
35    static const int INVALID_SET_ID;
36    enum SurfaceType{
37        SURFACE_TYPE_UNKNOWN = -1,
38        SURFACE_TYPE_SURFACE_VIEW = 0,
39        SURFACE_TYPE_SURFACE_TEXTURE = 1
40    };
41    const std::vector<sp<IGraphicBufferProducer>>& getGraphicBufferProducers() const;
42    int                        getRotation() const;
43    int                        getSurfaceSetID() const;
44    int                        getSurfaceType() const;
45    int                        getWidth() const;
46    int                        getHeight() const;
47    bool                       isDeferred() const;
48    bool                       isShared() const;
49    String16                   getPhysicalCameraId() const;
50    /**
51     * Keep impl up-to-date with OutputConfiguration.java in frameworks/base
52     */
53    virtual status_t           writeToParcel(android::Parcel* parcel) const override;
54
55    virtual status_t           readFromParcel(const android::Parcel* parcel) override;
56
57    // getGraphicBufferProducer will be NULL
58    // getRotation will be INVALID_ROTATION
59    // getSurfaceSetID will be INVALID_SET_ID
60    OutputConfiguration();
61
62    // getGraphicBufferProducer will be NULL if error occurred
63    // getRotation will be INVALID_ROTATION if error occurred
64    // getSurfaceSetID will be INVALID_SET_ID if error occurred
65    OutputConfiguration(const android::Parcel& parcel);
66
67    OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
68            int surfaceSetID = INVALID_SET_ID, bool isShared = false);
69
70    bool operator == (const OutputConfiguration& other) const {
71        return ( mRotation == other.mRotation &&
72                mSurfaceSetID == other.mSurfaceSetID &&
73                mSurfaceType == other.mSurfaceType &&
74                mWidth == other.mWidth &&
75                mHeight == other.mHeight &&
76                mIsDeferred == other.mIsDeferred &&
77                mIsShared == other.mIsShared &&
78                gbpsEqual(other) &&
79                mPhysicalCameraId == other.mPhysicalCameraId );
80    }
81    bool operator != (const OutputConfiguration& other) const {
82        return !(*this == other);
83    }
84    bool operator < (const OutputConfiguration& other) const {
85        if (*this == other) return false;
86        if (mSurfaceSetID != other.mSurfaceSetID) {
87            return mSurfaceSetID < other.mSurfaceSetID;
88        }
89        if (mSurfaceType != other.mSurfaceType) {
90            return mSurfaceType < other.mSurfaceType;
91        }
92        if (mWidth != other.mWidth) {
93            return mWidth < other.mWidth;
94        }
95        if (mHeight != other.mHeight) {
96            return mHeight < other.mHeight;
97        }
98        if (mRotation != other.mRotation) {
99            return mRotation < other.mRotation;
100        }
101        if (mIsDeferred != other.mIsDeferred) {
102            return mIsDeferred < other.mIsDeferred;
103        }
104        if (mIsShared != other.mIsShared) {
105            return mIsShared < other.mIsShared;
106        }
107        if (mPhysicalCameraId != other.mPhysicalCameraId) {
108            return mPhysicalCameraId < other.mPhysicalCameraId;
109        }
110        return gbpsLessThan(other);
111    }
112    bool operator > (const OutputConfiguration& other) const {
113        return (*this != other && !(*this < other));
114    }
115
116    bool gbpsEqual(const OutputConfiguration& other) const;
117    bool gbpsLessThan(const OutputConfiguration& other) const;
118    void addGraphicProducer(sp<IGraphicBufferProducer> gbp) {mGbps.push_back(gbp);}
119private:
120    std::vector<sp<IGraphicBufferProducer>> mGbps;
121    int                        mRotation;
122    int                        mSurfaceSetID;
123    int                        mSurfaceType;
124    int                        mWidth;
125    int                        mHeight;
126    bool                       mIsDeferred;
127    bool                       mIsShared;
128    String16                   mPhysicalCameraId;
129};
130} // namespace params
131} // namespace camera2
132} // namespace hardware
133
134
135using hardware::camera2::params::OutputConfiguration;
136
137}; // namespace android
138
139#endif
140