Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2015, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "OutputConfiguration" |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
| 20 | |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 21 | #include <utils/Log.h> |
| 22 | |
| 23 | #include <camera/camera2/OutputConfiguration.h> |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 24 | #include <gui/Surface.h> |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 25 | #include <binder/Parcel.h> |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | |
| 30 | const int OutputConfiguration::INVALID_ROTATION = -1; |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 31 | const int OutputConfiguration::INVALID_SET_ID = -1; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 32 | |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 33 | sp<IGraphicBufferProducer> OutputConfiguration::getGraphicBufferProducer() const { |
| 34 | return mGbp; |
| 35 | } |
| 36 | |
| 37 | int OutputConfiguration::getRotation() const { |
| 38 | return mRotation; |
| 39 | } |
| 40 | |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 41 | int OutputConfiguration::getSurfaceSetID() const { |
| 42 | return mSurfaceSetID; |
| 43 | } |
| 44 | |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 45 | int OutputConfiguration::getSurfaceType() const { |
| 46 | return mSurfaceType; |
| 47 | } |
| 48 | |
| 49 | int OutputConfiguration::getWidth() const { |
| 50 | return mWidth; |
| 51 | } |
| 52 | |
| 53 | int OutputConfiguration::getHeight() const { |
| 54 | return mHeight; |
| 55 | } |
| 56 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 57 | OutputConfiguration::OutputConfiguration() : |
| 58 | mRotation(INVALID_ROTATION), |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 59 | mSurfaceSetID(INVALID_SET_ID), |
| 60 | mSurfaceType(SURFACE_TYPE_UNKNOWN), |
| 61 | mWidth(0), |
| 62 | mHeight(0) { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame^] | 65 | OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) : |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 66 | mRotation(INVALID_ROTATION), |
| 67 | mSurfaceSetID(INVALID_SET_ID) { |
| 68 | readFromParcel(&parcel); |
| 69 | } |
| 70 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame^] | 71 | status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 72 | status_t err = OK; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 73 | int rotation = 0; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 74 | |
| 75 | if (parcel == nullptr) return BAD_VALUE; |
| 76 | |
| 77 | if ((err = parcel->readInt32(&rotation)) != OK) { |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 78 | ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 79 | return err; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 82 | int setID = INVALID_SET_ID; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 83 | if ((err = parcel->readInt32(&setID)) != OK) { |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 84 | ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 85 | return err; |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 88 | int surfaceType = SURFACE_TYPE_UNKNOWN; |
| 89 | if ((err = parcel->readInt32(&surfaceType)) != OK) { |
| 90 | ALOGE("%s: Failed to read surface type from parcel", __FUNCTION__); |
| 91 | return err; |
| 92 | } |
| 93 | |
| 94 | int width = 0; |
| 95 | if ((err = parcel->readInt32(&width)) != OK) { |
| 96 | ALOGE("%s: Failed to read surface width from parcel", __FUNCTION__); |
| 97 | return err; |
| 98 | } |
| 99 | |
| 100 | int height = 0; |
| 101 | if ((err = parcel->readInt32(&height)) != OK) { |
| 102 | ALOGE("%s: Failed to read surface height from parcel", __FUNCTION__); |
| 103 | return err; |
| 104 | } |
| 105 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 106 | view::Surface surfaceShim; |
| 107 | if ((err = surfaceShim.readFromParcel(parcel)) != OK) { |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 108 | // Read surface failure for deferred surface configuration is expected. |
| 109 | if (surfaceType == SURFACE_TYPE_SURFACE_VIEW || |
| 110 | surfaceType == SURFACE_TYPE_SURFACE_TEXTURE) { |
| 111 | ALOGV("%s: Get null surface from a deferred surface configuration (%dx%d)", |
| 112 | __FUNCTION__, width, height); |
| 113 | err = OK; |
| 114 | } else { |
| 115 | ALOGE("%s: Failed to read surface from parcel", __FUNCTION__); |
| 116 | return err; |
| 117 | } |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | mGbp = surfaceShim.graphicBufferProducer; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 121 | mRotation = rotation; |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 122 | mSurfaceSetID = setID; |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 123 | mSurfaceType = surfaceType; |
| 124 | mWidth = width; |
| 125 | mHeight = height; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 126 | |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 127 | ALOGV("%s: OutputConfiguration: bp = %p, name = %s, rotation = %d, setId = %d," |
| 128 | "surfaceType = %d", __FUNCTION__, mGbp.get(), String8(surfaceShim.name).string(), |
| 129 | mRotation, mSurfaceSetID, mSurfaceType); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 130 | |
| 131 | return err; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 134 | OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation, |
| 135 | int surfaceSetID) { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 136 | mGbp = gbp; |
| 137 | mRotation = rotation; |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 138 | mSurfaceSetID = surfaceSetID; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame^] | 141 | status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const { |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 142 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 143 | if (parcel == nullptr) return BAD_VALUE; |
| 144 | status_t err = OK; |
| 145 | |
| 146 | err = parcel->writeInt32(mRotation); |
| 147 | if (err != OK) return err; |
| 148 | |
| 149 | err = parcel->writeInt32(mSurfaceSetID); |
| 150 | if (err != OK) return err; |
| 151 | |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 152 | err = parcel->writeInt32(mSurfaceType); |
| 153 | if (err != OK) return err; |
| 154 | |
| 155 | err = parcel->writeInt32(mWidth); |
| 156 | if (err != OK) return err; |
| 157 | |
| 158 | err = parcel->writeInt32(mHeight); |
| 159 | if (err != OK) return err; |
| 160 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 161 | view::Surface surfaceShim; |
| 162 | surfaceShim.name = String16("unknown_name"); // name of surface |
| 163 | surfaceShim.graphicBufferProducer = mGbp; |
| 164 | |
| 165 | err = surfaceShim.writeToParcel(parcel); |
| 166 | if (err != OK) return err; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 167 | |
| 168 | return OK; |
| 169 | } |
| 170 | |
| 171 | }; // namespace android |