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 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 45 | OutputConfiguration::OutputConfiguration() : |
| 46 | mRotation(INVALID_ROTATION), |
| 47 | mSurfaceSetID(INVALID_SET_ID) { |
| 48 | } |
| 49 | |
| 50 | OutputConfiguration::OutputConfiguration(const Parcel& parcel) : |
| 51 | mRotation(INVALID_ROTATION), |
| 52 | mSurfaceSetID(INVALID_SET_ID) { |
| 53 | readFromParcel(&parcel); |
| 54 | } |
| 55 | |
| 56 | status_t OutputConfiguration::readFromParcel(const Parcel* parcel) { |
| 57 | status_t err = OK; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 58 | int rotation = 0; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 59 | |
| 60 | if (parcel == nullptr) return BAD_VALUE; |
| 61 | |
| 62 | if ((err = parcel->readInt32(&rotation)) != OK) { |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 63 | ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 64 | return err; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 67 | int setID = INVALID_SET_ID; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 68 | if ((err = parcel->readInt32(&setID)) != OK) { |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 69 | ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 70 | return err; |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 73 | view::Surface surfaceShim; |
| 74 | if ((err = surfaceShim.readFromParcel(parcel)) != OK) { |
| 75 | ALOGE("%s: Failed to read surface from parcel", __FUNCTION__); |
| 76 | return err; |
| 77 | } |
| 78 | |
| 79 | mGbp = surfaceShim.graphicBufferProducer; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 80 | mRotation = rotation; |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 81 | mSurfaceSetID = setID; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 82 | |
Eino-Ville Talvala | 02bf032 | 2016-02-18 12:41:10 -0800 | [diff] [blame] | 83 | ALOGV("%s: OutputConfiguration: bp = %p, name = %s, rotation = %d, setId = %d", __FUNCTION__, |
| 84 | mGbp.get(), String8(surfaceShim.name).string(), mRotation, mSurfaceSetID); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 85 | |
| 86 | return err; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 89 | OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation, |
| 90 | int surfaceSetID) { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 91 | mGbp = gbp; |
| 92 | mRotation = rotation; |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 93 | mSurfaceSetID = surfaceSetID; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 96 | status_t OutputConfiguration::writeToParcel(Parcel* parcel) const { |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 97 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 98 | if (parcel == nullptr) return BAD_VALUE; |
| 99 | status_t err = OK; |
| 100 | |
| 101 | err = parcel->writeInt32(mRotation); |
| 102 | if (err != OK) return err; |
| 103 | |
| 104 | err = parcel->writeInt32(mSurfaceSetID); |
| 105 | if (err != OK) return err; |
| 106 | |
| 107 | view::Surface surfaceShim; |
| 108 | surfaceShim.name = String16("unknown_name"); // name of surface |
| 109 | surfaceShim.graphicBufferProducer = mGbp; |
| 110 | |
| 111 | err = surfaceShim.writeToParcel(parcel); |
| 112 | if (err != OK) return err; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 113 | |
| 114 | return OK; |
| 115 | } |
| 116 | |
| 117 | }; // namespace android |