OutputConfiguration.cpp revision 02bf03287652923b5bb5316667b065423565d6b4
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
27namespace android {
28
29
30const int OutputConfiguration::INVALID_ROTATION = -1;
31const int OutputConfiguration::INVALID_SET_ID = -1;
32
33sp<IGraphicBufferProducer> OutputConfiguration::getGraphicBufferProducer() const {
34    return mGbp;
35}
36
37int OutputConfiguration::getRotation() const {
38    return mRotation;
39}
40
41int OutputConfiguration::getSurfaceSetID() const {
42    return mSurfaceSetID;
43}
44
45OutputConfiguration::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;
58    int rotation = 0;
59
60    if (parcel == nullptr) return BAD_VALUE;
61
62    if ((err = parcel->readInt32(&rotation)) != OK) {
63        ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
64        return err;
65    }
66
67    int setID = INVALID_SET_ID;
68    if ((err = parcel->readInt32(&setID)) != OK) {
69        ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
70        return err;
71    }
72
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;
80    mRotation = rotation;
81    mSurfaceSetID = setID;
82
83    ALOGV("%s: OutputConfiguration: bp = %p, name = %s, rotation = %d, setId = %d", __FUNCTION__,
84            mGbp.get(), String8(surfaceShim.name).string(), mRotation, mSurfaceSetID);
85
86    return err;
87}
88
89OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
90        int surfaceSetID) {
91    mGbp = gbp;
92    mRotation = rotation;
93    mSurfaceSetID = surfaceSetID;
94}
95
96status_t OutputConfiguration::writeToParcel(Parcel* parcel) const {
97
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;
113
114    return OK;
115}
116
117}; // namespace android
118