blob: f4f2229654c267b92322f717034fb1d7cf54f89b [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>
24#include <binder/Parcel.h>
Brian Andersonf6753562016-10-11 14:51:05 -070025#include <gui/Surface.h>
26#include <utils/String8.h>
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070027
28namespace android {
29
30
31const int OutputConfiguration::INVALID_ROTATION = -1;
Zhijun He018107a2016-01-18 15:32:50 -080032const int OutputConfiguration::INVALID_SET_ID = -1;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070033
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070034sp<IGraphicBufferProducer> OutputConfiguration::getGraphicBufferProducer() const {
35 return mGbp;
36}
37
38int OutputConfiguration::getRotation() const {
39 return mRotation;
40}
41
Zhijun He018107a2016-01-18 15:32:50 -080042int OutputConfiguration::getSurfaceSetID() const {
43 return mSurfaceSetID;
44}
45
Zhijun He5d677d12016-05-29 16:52:39 -070046int OutputConfiguration::getSurfaceType() const {
47 return mSurfaceType;
48}
49
50int OutputConfiguration::getWidth() const {
51 return mWidth;
52}
53
54int OutputConfiguration::getHeight() const {
55 return mHeight;
56}
57
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080058OutputConfiguration::OutputConfiguration() :
59 mRotation(INVALID_ROTATION),
Zhijun He5d677d12016-05-29 16:52:39 -070060 mSurfaceSetID(INVALID_SET_ID),
61 mSurfaceType(SURFACE_TYPE_UNKNOWN),
62 mWidth(0),
63 mHeight(0) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080064}
65
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080066OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080067 mRotation(INVALID_ROTATION),
68 mSurfaceSetID(INVALID_SET_ID) {
69 readFromParcel(&parcel);
70}
71
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080072status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080073 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070074 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080075
76 if (parcel == nullptr) return BAD_VALUE;
77
78 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070079 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080080 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070081 }
82
Zhijun He018107a2016-01-18 15:32:50 -080083 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080084 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -080085 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080086 return err;
Zhijun He018107a2016-01-18 15:32:50 -080087 }
88
Zhijun He5d677d12016-05-29 16:52:39 -070089 int surfaceType = SURFACE_TYPE_UNKNOWN;
90 if ((err = parcel->readInt32(&surfaceType)) != OK) {
91 ALOGE("%s: Failed to read surface type from parcel", __FUNCTION__);
92 return err;
93 }
94
95 int width = 0;
96 if ((err = parcel->readInt32(&width)) != OK) {
97 ALOGE("%s: Failed to read surface width from parcel", __FUNCTION__);
98 return err;
99 }
100
101 int height = 0;
102 if ((err = parcel->readInt32(&height)) != OK) {
103 ALOGE("%s: Failed to read surface height from parcel", __FUNCTION__);
104 return err;
105 }
106
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800107 view::Surface surfaceShim;
108 if ((err = surfaceShim.readFromParcel(parcel)) != OK) {
Zhijun He5d677d12016-05-29 16:52:39 -0700109 // Read surface failure for deferred surface configuration is expected.
110 if (surfaceType == SURFACE_TYPE_SURFACE_VIEW ||
111 surfaceType == SURFACE_TYPE_SURFACE_TEXTURE) {
112 ALOGV("%s: Get null surface from a deferred surface configuration (%dx%d)",
113 __FUNCTION__, width, height);
114 err = OK;
115 } else {
116 ALOGE("%s: Failed to read surface from parcel", __FUNCTION__);
117 return err;
118 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800119 }
120
121 mGbp = surfaceShim.graphicBufferProducer;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700122 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800123 mSurfaceSetID = setID;
Zhijun He5d677d12016-05-29 16:52:39 -0700124 mSurfaceType = surfaceType;
125 mWidth = width;
126 mHeight = height;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700127
Zhijun He5d677d12016-05-29 16:52:39 -0700128 ALOGV("%s: OutputConfiguration: bp = %p, name = %s, rotation = %d, setId = %d,"
129 "surfaceType = %d", __FUNCTION__, mGbp.get(), String8(surfaceShim.name).string(),
130 mRotation, mSurfaceSetID, mSurfaceType);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800131
132 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700133}
134
Zhijun He018107a2016-01-18 15:32:50 -0800135OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
136 int surfaceSetID) {
Ruben Brunk3450ba72015-06-16 11:00:37 -0700137 mGbp = gbp;
138 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800139 mSurfaceSetID = surfaceSetID;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700140}
141
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800142status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700143
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800144 if (parcel == nullptr) return BAD_VALUE;
145 status_t err = OK;
146
147 err = parcel->writeInt32(mRotation);
148 if (err != OK) return err;
149
150 err = parcel->writeInt32(mSurfaceSetID);
151 if (err != OK) return err;
152
Zhijun He5d677d12016-05-29 16:52:39 -0700153 err = parcel->writeInt32(mSurfaceType);
154 if (err != OK) return err;
155
156 err = parcel->writeInt32(mWidth);
157 if (err != OK) return err;
158
159 err = parcel->writeInt32(mHeight);
160 if (err != OK) return err;
161
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800162 view::Surface surfaceShim;
163 surfaceShim.name = String16("unknown_name"); // name of surface
164 surfaceShim.graphicBufferProducer = mGbp;
165
166 err = surfaceShim.writeToParcel(parcel);
167 if (err != OK) return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700168
169 return OK;
170}
171
172}; // namespace android