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 23 namespace android { 24 25 class Surface; 26 27 namespace hardware { 28 namespace camera2 { 29 namespace params { 30 31 class OutputConfiguration : public android::Parcelable { 32 public: 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 bool isMultiResolution() const; 51 52 // set of sensor pixel mode resolutions allowed {MAX_RESOLUTION, DEFAULT_MODE}; 53 const std::vector<int32_t>& getSensorPixelModesUsed() const; 54 /** 55 * Keep impl up-to-date with OutputConfiguration.java in frameworks/base 56 */ 57 virtual status_t writeToParcel(android::Parcel* parcel) const override; 58 59 virtual status_t readFromParcel(const android::Parcel* parcel) override; 60 61 // getGraphicBufferProducer will be NULL 62 // getRotation will be INVALID_ROTATION 63 // getSurfaceSetID will be INVALID_SET_ID 64 OutputConfiguration(); 65 66 // getGraphicBufferProducer will be NULL if error occurred 67 // getRotation will be INVALID_ROTATION if error occurred 68 // getSurfaceSetID will be INVALID_SET_ID if error occurred 69 OutputConfiguration(const android::Parcel& parcel); 70 71 OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation, 72 const String16& physicalCameraId, 73 int surfaceSetID = INVALID_SET_ID, bool isShared = false); 74 75 OutputConfiguration(const std::vector<sp<IGraphicBufferProducer>>& gbps, 76 int rotation, const String16& physicalCameraId, 77 int surfaceSetID = INVALID_SET_ID, 78 int surfaceType = OutputConfiguration::SURFACE_TYPE_UNKNOWN, int width = 0, 79 int height = 0, bool isShared = false); 80 81 bool operator == (const OutputConfiguration& other) const { 82 return ( mRotation == other.mRotation && 83 mSurfaceSetID == other.mSurfaceSetID && 84 mSurfaceType == other.mSurfaceType && 85 mWidth == other.mWidth && 86 mHeight == other.mHeight && 87 mIsDeferred == other.mIsDeferred && 88 mIsShared == other.mIsShared && 89 gbpsEqual(other) && 90 mPhysicalCameraId == other.mPhysicalCameraId && 91 mIsMultiResolution == other.mIsMultiResolution && 92 sensorPixelModesUsedEqual(other)); 93 } 94 bool operator != (const OutputConfiguration& other) const { 95 return !(*this == other); 96 } 97 bool operator < (const OutputConfiguration& other) const { 98 if (*this == other) return false; 99 if (mSurfaceSetID != other.mSurfaceSetID) { 100 return mSurfaceSetID < other.mSurfaceSetID; 101 } 102 if (mSurfaceType != other.mSurfaceType) { 103 return mSurfaceType < other.mSurfaceType; 104 } 105 if (mWidth != other.mWidth) { 106 return mWidth < other.mWidth; 107 } 108 if (mHeight != other.mHeight) { 109 return mHeight < other.mHeight; 110 } 111 if (mRotation != other.mRotation) { 112 return mRotation < other.mRotation; 113 } 114 if (mIsDeferred != other.mIsDeferred) { 115 return mIsDeferred < other.mIsDeferred; 116 } 117 if (mIsShared != other.mIsShared) { 118 return mIsShared < other.mIsShared; 119 } 120 if (mPhysicalCameraId != other.mPhysicalCameraId) { 121 return mPhysicalCameraId < other.mPhysicalCameraId; 122 } 123 if (mIsMultiResolution != other.mIsMultiResolution) { 124 return mIsMultiResolution < other.mIsMultiResolution; 125 } 126 if (!sensorPixelModesUsedEqual(other)) { 127 return sensorPixelModesUsedLessThan(other); 128 } 129 return gbpsLessThan(other); 130 } 131 132 bool operator > (const OutputConfiguration& other) const { 133 return (*this != other && !(*this < other)); 134 } 135 136 bool gbpsEqual(const OutputConfiguration& other) const; 137 bool sensorPixelModesUsedEqual(const OutputConfiguration& other) const; 138 bool sensorPixelModesUsedLessThan(const OutputConfiguration& other) const; 139 bool gbpsLessThan(const OutputConfiguration& other) const; addGraphicProducer(sp<IGraphicBufferProducer> gbp)140 void addGraphicProducer(sp<IGraphicBufferProducer> gbp) {mGbps.push_back(gbp);} 141 private: 142 std::vector<sp<IGraphicBufferProducer>> mGbps; 143 int mRotation; 144 int mSurfaceSetID; 145 int mSurfaceType; 146 int mWidth; 147 int mHeight; 148 bool mIsDeferred; 149 bool mIsShared; 150 String16 mPhysicalCameraId; 151 bool mIsMultiResolution; 152 std::vector<int32_t> mSensorPixelModesUsed; 153 }; 154 } // namespace params 155 } // namespace camera2 156 } // namespace hardware 157 158 159 using hardware::camera2::params::OutputConfiguration; 160 161 }; // namespace android 162 163 #endif 164