1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2010 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_GUI_VIEW_SURFACE_H 18*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_GUI_VIEW_SURFACE_H 19*38e8c45fSAndroid Build Coastguard Worker 20*38e8c45fSAndroid Build Coastguard Worker #include <utils/Errors.h> 21*38e8c45fSAndroid Build Coastguard Worker #include <utils/StrongPointer.h> 22*38e8c45fSAndroid Build Coastguard Worker #include <utils/String16.h> 23*38e8c45fSAndroid Build Coastguard Worker 24*38e8c45fSAndroid Build Coastguard Worker #include <binder/IBinder.h> 25*38e8c45fSAndroid Build Coastguard Worker #include <binder/Parcelable.h> 26*38e8c45fSAndroid Build Coastguard Worker 27*38e8c45fSAndroid Build Coastguard Worker #include <gui/Flags.h> 28*38e8c45fSAndroid Build Coastguard Worker #include <gui/IGraphicBufferProducer.h> 29*38e8c45fSAndroid Build Coastguard Worker #include <gui/Surface.h> 30*38e8c45fSAndroid Build Coastguard Worker 31*38e8c45fSAndroid Build Coastguard Worker namespace android { 32*38e8c45fSAndroid Build Coastguard Worker 33*38e8c45fSAndroid Build Coastguard Worker namespace view { 34*38e8c45fSAndroid Build Coastguard Worker 35*38e8c45fSAndroid Build Coastguard Worker /** 36*38e8c45fSAndroid Build Coastguard Worker * A simple holder for an IGraphicBufferProducer, to match the managed-side 37*38e8c45fSAndroid Build Coastguard Worker * android.view.Surface parcelable behavior. 38*38e8c45fSAndroid Build Coastguard Worker * 39*38e8c45fSAndroid Build Coastguard Worker * This implements android/view/Surface.aidl 40*38e8c45fSAndroid Build Coastguard Worker * 41*38e8c45fSAndroid Build Coastguard Worker * TODO: Convert IGraphicBufferProducer into AIDL so that it can be directly 42*38e8c45fSAndroid Build Coastguard Worker * used in managed Binder calls. 43*38e8c45fSAndroid Build Coastguard Worker */ 44*38e8c45fSAndroid Build Coastguard Worker class Surface : public Parcelable { 45*38e8c45fSAndroid Build Coastguard Worker public: 46*38e8c45fSAndroid Build Coastguard Worker 47*38e8c45fSAndroid Build Coastguard Worker String16 name; 48*38e8c45fSAndroid Build Coastguard Worker sp<IGraphicBufferProducer> graphicBufferProducer; 49*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> surfaceControlHandle; 50*38e8c45fSAndroid Build Coastguard Worker 51*38e8c45fSAndroid Build Coastguard Worker #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES 52*38e8c45fSAndroid Build Coastguard Worker // functions used to convert to a parcelable Surface so it can be passed over binder. 53*38e8c45fSAndroid Build Coastguard Worker static Surface fromSurface(const sp<android::Surface>& surface); 54*38e8c45fSAndroid Build Coastguard Worker sp<android::Surface> toSurface() const; 55*38e8c45fSAndroid Build Coastguard Worker 56*38e8c45fSAndroid Build Coastguard Worker status_t getUniqueId(/* out */ uint64_t* id) const; 57*38e8c45fSAndroid Build Coastguard Worker 58*38e8c45fSAndroid Build Coastguard Worker bool isEmpty() const; 59*38e8c45fSAndroid Build Coastguard Worker 60*38e8c45fSAndroid Build Coastguard Worker bool operator==(const Surface& other) const { 61*38e8c45fSAndroid Build Coastguard Worker return graphicBufferProducer == other.graphicBufferProducer; 62*38e8c45fSAndroid Build Coastguard Worker } 63*38e8c45fSAndroid Build Coastguard Worker bool operator!=(const Surface& other) const { return !(*this == other); } 64*38e8c45fSAndroid Build Coastguard Worker bool operator==(const sp<android::Surface> other) const { 65*38e8c45fSAndroid Build Coastguard Worker if (other == nullptr) return graphicBufferProducer == nullptr; 66*38e8c45fSAndroid Build Coastguard Worker return graphicBufferProducer == other->getIGraphicBufferProducer(); 67*38e8c45fSAndroid Build Coastguard Worker } 68*38e8c45fSAndroid Build Coastguard Worker bool operator!=(const sp<android::Surface> other) const { return !(*this == other); } 69*38e8c45fSAndroid Build Coastguard Worker bool operator<(const Surface& other) const { 70*38e8c45fSAndroid Build Coastguard Worker return graphicBufferProducer < other.graphicBufferProducer; 71*38e8c45fSAndroid Build Coastguard Worker } 72*38e8c45fSAndroid Build Coastguard Worker bool operator>(const Surface& other) const { return other < *this; } 73*38e8c45fSAndroid Build Coastguard Worker #endif 74*38e8c45fSAndroid Build Coastguard Worker 75*38e8c45fSAndroid Build Coastguard Worker virtual status_t writeToParcel(Parcel* parcel) const override; 76*38e8c45fSAndroid Build Coastguard Worker virtual status_t readFromParcel(const Parcel* parcel) override; 77*38e8c45fSAndroid Build Coastguard Worker 78*38e8c45fSAndroid Build Coastguard Worker // nameAlreadyWritten set to true by Surface.java, because it splits 79*38e8c45fSAndroid Build Coastguard Worker // Parceling itself between managed and native code, so it only wants a part 80*38e8c45fSAndroid Build Coastguard Worker // of the full parceling to happen on its native side. 81*38e8c45fSAndroid Build Coastguard Worker status_t writeToParcel(Parcel* parcel, bool nameAlreadyWritten) const; 82*38e8c45fSAndroid Build Coastguard Worker 83*38e8c45fSAndroid Build Coastguard Worker // nameAlreadyRead set to true by Surface.java, because it splits 84*38e8c45fSAndroid Build Coastguard Worker // Parceling itself between managed and native code, so it only wants a part 85*38e8c45fSAndroid Build Coastguard Worker // of the full parceling to happen on its native side. 86*38e8c45fSAndroid Build Coastguard Worker status_t readFromParcel(const Parcel* parcel, bool nameAlreadyRead); 87*38e8c45fSAndroid Build Coastguard Worker 88*38e8c45fSAndroid Build Coastguard Worker std::string toString() const; 89*38e8c45fSAndroid Build Coastguard Worker 90*38e8c45fSAndroid Build Coastguard Worker private: 91*38e8c45fSAndroid Build Coastguard Worker static String16 readMaybeEmptyString16(const Parcel* parcel); 92*38e8c45fSAndroid Build Coastguard Worker }; 93*38e8c45fSAndroid Build Coastguard Worker 94*38e8c45fSAndroid Build Coastguard Worker } // namespace view 95*38e8c45fSAndroid Build Coastguard Worker } // namespace android 96*38e8c45fSAndroid Build Coastguard Worker 97*38e8c45fSAndroid Build Coastguard Worker #endif // ANDROID_GUI_VIEW_SURFACE_H 98