Surface.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2010 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #define LOG_TAG "Surface"
  17. #include <gui/view/Surface.h>
  18. #include <binder/Parcel.h>
  19. #include <utils/Log.h>
  20. #include <gui/IGraphicBufferProducer.h>
  21. namespace android {
  22. namespace view {
  23. status_t Surface::writeToParcel(Parcel* parcel) const {
  24. return writeToParcel(parcel, false);
  25. }
  26. status_t Surface::writeToParcel(Parcel* parcel, bool nameAlreadyWritten) const {
  27. if (parcel == nullptr) return BAD_VALUE;
  28. status_t res = OK;
  29. if (!nameAlreadyWritten) {
  30. res = parcel->writeString16(name);
  31. if (res != OK) return res;
  32. /* isSingleBuffered defaults to no */
  33. res = parcel->writeInt32(0);
  34. if (res != OK) return res;
  35. }
  36. return IGraphicBufferProducer::exportToParcel(graphicBufferProducer, parcel);
  37. }
  38. status_t Surface::readFromParcel(const Parcel* parcel) {
  39. return readFromParcel(parcel, false);
  40. }
  41. status_t Surface::readFromParcel(const Parcel* parcel, bool nameAlreadyRead) {
  42. if (parcel == nullptr) return BAD_VALUE;
  43. status_t res = OK;
  44. if (!nameAlreadyRead) {
  45. name = readMaybeEmptyString16(parcel);
  46. // Discard this for now
  47. int isSingleBuffered;
  48. res = parcel->readInt32(&isSingleBuffered);
  49. if (res != OK) {
  50. ALOGE("Can't read isSingleBuffered");
  51. return res;
  52. }
  53. }
  54. graphicBufferProducer = IGraphicBufferProducer::createFromParcel(parcel);
  55. return OK;
  56. }
  57. String16 Surface::readMaybeEmptyString16(const Parcel* parcel) {
  58. size_t len;
  59. const char16_t* str = parcel->readString16Inplace(&len);
  60. if (str != nullptr) {
  61. return String16(str, len);
  62. } else {
  63. return String16();
  64. }
  65. }
  66. } // namespace view
  67. } // namespace android