blob: 3247d0dee9373c49457d729e23b0730db2d859cc [file] [log] [blame]
Yin-Chia Yehb97babb2015-03-12 13:42:44 -07001/*
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 Talvalad56db1d2015-12-17 16:50:35 -080019//#define LOG_NDEBUG 0
20
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070021#include <utils/Log.h>
22
23#include <camera/camera2/OutputConfiguration.h>
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080024#include <gui/Surface.h>
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070025#include <binder/Parcel.h>
26
27namespace android {
28
29
30const int OutputConfiguration::INVALID_ROTATION = -1;
Zhijun He018107a2016-01-18 15:32:50 -080031const int OutputConfiguration::INVALID_SET_ID = -1;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070032
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070033sp<IGraphicBufferProducer> OutputConfiguration::getGraphicBufferProducer() const {
34 return mGbp;
35}
36
37int OutputConfiguration::getRotation() const {
38 return mRotation;
39}
40
Zhijun He018107a2016-01-18 15:32:50 -080041int OutputConfiguration::getSurfaceSetID() const {
42 return mSurfaceSetID;
43}
44
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080045OutputConfiguration::OutputConfiguration() :
46 mRotation(INVALID_ROTATION),
47 mSurfaceSetID(INVALID_SET_ID) {
48}
49
50OutputConfiguration::OutputConfiguration(const Parcel& parcel) :
51 mRotation(INVALID_ROTATION),
52 mSurfaceSetID(INVALID_SET_ID) {
53 readFromParcel(&parcel);
54}
55
56status_t OutputConfiguration::readFromParcel(const Parcel* parcel) {
57 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070058 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080059
60 if (parcel == nullptr) return BAD_VALUE;
61
62 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070063 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080064 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070065 }
66
Zhijun He018107a2016-01-18 15:32:50 -080067 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080068 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -080069 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080070 return err;
Zhijun He018107a2016-01-18 15:32:50 -080071 }
72
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080073 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 Yehb97babb2015-03-12 13:42:44 -070080 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -080081 mSurfaceSetID = setID;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070082
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -080083 ALOGV("%s: OutputConfiguration: bp = %p, name = %s, rotation = %d, setId = %d", __FUNCTION__,
84 mGbp.get(), String8(surfaceShim.name).string(), mRotation, mSurfaceSetID);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080085
86 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070087}
88
Zhijun He018107a2016-01-18 15:32:50 -080089OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
90 int surfaceSetID) {
Ruben Brunk3450ba72015-06-16 11:00:37 -070091 mGbp = gbp;
92 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -080093 mSurfaceSetID = surfaceSetID;
Ruben Brunk3450ba72015-06-16 11:00:37 -070094}
95
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080096status_t OutputConfiguration::writeToParcel(Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070097
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080098 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 Yehb97babb2015-03-12 13:42:44 -0700113
114 return OK;
115}
116
117}; // namespace android