blob: 12d0da85b4f4835715bd59ad6399a1a49f6c2cef [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
Zhijun He5d677d12016-05-29 16:52:39 -070045int OutputConfiguration::getSurfaceType() const {
46 return mSurfaceType;
47}
48
49int OutputConfiguration::getWidth() const {
50 return mWidth;
51}
52
53int OutputConfiguration::getHeight() const {
54 return mHeight;
55}
56
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080057OutputConfiguration::OutputConfiguration() :
58 mRotation(INVALID_ROTATION),
Zhijun He5d677d12016-05-29 16:52:39 -070059 mSurfaceSetID(INVALID_SET_ID),
60 mSurfaceType(SURFACE_TYPE_UNKNOWN),
61 mWidth(0),
62 mHeight(0) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080063}
64
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080065OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080066 mRotation(INVALID_ROTATION),
67 mSurfaceSetID(INVALID_SET_ID) {
68 readFromParcel(&parcel);
69}
70
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080071status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080072 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070073 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080074
75 if (parcel == nullptr) return BAD_VALUE;
76
77 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070078 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080079 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070080 }
81
Zhijun He018107a2016-01-18 15:32:50 -080082 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080083 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -080084 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080085 return err;
Zhijun He018107a2016-01-18 15:32:50 -080086 }
87
Zhijun He5d677d12016-05-29 16:52:39 -070088 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 Talvalad56db1d2015-12-17 16:50:35 -0800106 view::Surface surfaceShim;
107 if ((err = surfaceShim.readFromParcel(parcel)) != OK) {
Zhijun He5d677d12016-05-29 16:52:39 -0700108 // 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 Talvalad56db1d2015-12-17 16:50:35 -0800118 }
119
120 mGbp = surfaceShim.graphicBufferProducer;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700121 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800122 mSurfaceSetID = setID;
Zhijun He5d677d12016-05-29 16:52:39 -0700123 mSurfaceType = surfaceType;
124 mWidth = width;
125 mHeight = height;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700126
Zhijun He5d677d12016-05-29 16:52:39 -0700127 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 Talvalad56db1d2015-12-17 16:50:35 -0800130
131 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700132}
133
Zhijun He018107a2016-01-18 15:32:50 -0800134OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
135 int surfaceSetID) {
Ruben Brunk3450ba72015-06-16 11:00:37 -0700136 mGbp = gbp;
137 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800138 mSurfaceSetID = surfaceSetID;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700139}
140
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800141status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700142
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800143 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 He5d677d12016-05-29 16:52:39 -0700152 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 Talvalad56db1d2015-12-17 16:50:35 -0800161 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 Yehb97babb2015-03-12 13:42:44 -0700167
168 return OK;
169}
170
171}; // namespace android