• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
19 //#define LOG_NDEBUG 0
20 
21 #include <utils/Log.h>
22 
23 #include <camera/camera2/OutputConfiguration.h>
24 #include <gui/Surface.h>
25 #include <binder/Parcel.h>
26 
27 namespace android {
28 
29 
30 const int OutputConfiguration::INVALID_ROTATION = -1;
31 const int OutputConfiguration::INVALID_SET_ID = -1;
32 
getGraphicBufferProducer() const33 sp<IGraphicBufferProducer> OutputConfiguration::getGraphicBufferProducer() const {
34     return mGbp;
35 }
36 
getRotation() const37 int OutputConfiguration::getRotation() const {
38     return mRotation;
39 }
40 
getSurfaceSetID() const41 int OutputConfiguration::getSurfaceSetID() const {
42     return mSurfaceSetID;
43 }
44 
getSurfaceType() const45 int OutputConfiguration::getSurfaceType() const {
46     return mSurfaceType;
47 }
48 
getWidth() const49 int OutputConfiguration::getWidth() const {
50     return mWidth;
51 }
52 
getHeight() const53 int OutputConfiguration::getHeight() const {
54     return mHeight;
55 }
56 
OutputConfiguration()57 OutputConfiguration::OutputConfiguration() :
58         mRotation(INVALID_ROTATION),
59         mSurfaceSetID(INVALID_SET_ID),
60         mSurfaceType(SURFACE_TYPE_UNKNOWN),
61         mWidth(0),
62         mHeight(0) {
63 }
64 
OutputConfiguration(const Parcel & parcel)65 OutputConfiguration::OutputConfiguration(const Parcel& parcel) :
66         mRotation(INVALID_ROTATION),
67         mSurfaceSetID(INVALID_SET_ID) {
68     readFromParcel(&parcel);
69 }
70 
readFromParcel(const Parcel * parcel)71 status_t OutputConfiguration::readFromParcel(const Parcel* parcel) {
72     status_t err = OK;
73     int rotation = 0;
74 
75     if (parcel == nullptr) return BAD_VALUE;
76 
77     if ((err = parcel->readInt32(&rotation)) != OK) {
78         ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
79         return err;
80     }
81 
82     int setID = INVALID_SET_ID;
83     if ((err = parcel->readInt32(&setID)) != OK) {
84         ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
85         return err;
86     }
87 
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 
106     view::Surface surfaceShim;
107     if ((err = surfaceShim.readFromParcel(parcel)) != OK) {
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         }
118     }
119 
120     mGbp = surfaceShim.graphicBufferProducer;
121     mRotation = rotation;
122     mSurfaceSetID = setID;
123     mSurfaceType = surfaceType;
124     mWidth = width;
125     mHeight = height;
126 
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);
130 
131     return err;
132 }
133 
OutputConfiguration(sp<IGraphicBufferProducer> & gbp,int rotation,int surfaceSetID)134 OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
135         int surfaceSetID) {
136     mGbp = gbp;
137     mRotation = rotation;
138     mSurfaceSetID = surfaceSetID;
139 }
140 
writeToParcel(Parcel * parcel) const141 status_t OutputConfiguration::writeToParcel(Parcel* parcel) const {
142 
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 
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 
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;
167 
168     return OK;
169 }
170 
171 }; // namespace android
172