FrameStats.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2014 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. #include <ui/FrameStats.h>
  17. namespace android {
  18. bool FrameStats::isFixedSize() const {
  19. return false;
  20. }
  21. size_t FrameStats::getFlattenedSize() const {
  22. const size_t timestampSize = sizeof(nsecs_t);
  23. size_t size = timestampSize;
  24. size += 3 * desiredPresentTimesNano.size() * timestampSize;
  25. return size;
  26. }
  27. status_t FrameStats::flatten(void* buffer, size_t size) const {
  28. if (size < getFlattenedSize()) {
  29. return NO_MEMORY;
  30. }
  31. nsecs_t* timestamps = reinterpret_cast<nsecs_t*>(buffer);
  32. const size_t timestampSize = sizeof(nsecs_t);
  33. size_t frameCount = desiredPresentTimesNano.size();
  34. memcpy(timestamps, &refreshPeriodNano, timestampSize);
  35. timestamps += 1;
  36. memcpy(timestamps, desiredPresentTimesNano.array(), frameCount * timestampSize);
  37. timestamps += frameCount;
  38. memcpy(timestamps, actualPresentTimesNano.array(), frameCount * timestampSize);
  39. timestamps += frameCount;
  40. memcpy(timestamps, frameReadyTimesNano.array(), frameCount * timestampSize);
  41. return NO_ERROR;
  42. }
  43. status_t FrameStats::unflatten(void const* buffer, size_t size) {
  44. const size_t timestampSize = sizeof(nsecs_t);
  45. if (size < timestampSize) {
  46. return NO_MEMORY;
  47. }
  48. nsecs_t const* timestamps = reinterpret_cast<nsecs_t const*>(buffer);
  49. size_t frameCount = (size - timestampSize) / (3 * timestampSize);
  50. memcpy(&refreshPeriodNano, timestamps, timestampSize);
  51. timestamps += 1;
  52. desiredPresentTimesNano.resize(frameCount);
  53. memcpy(desiredPresentTimesNano.editArray(), timestamps, frameCount * timestampSize);
  54. timestamps += frameCount;
  55. actualPresentTimesNano.resize(frameCount);
  56. memcpy(actualPresentTimesNano.editArray(), timestamps, frameCount * timestampSize);
  57. timestamps += frameCount;
  58. frameReadyTimesNano.resize(frameCount);
  59. memcpy(frameReadyTimesNano.editArray(), timestamps, frameCount * timestampSize);
  60. return NO_ERROR;
  61. }
  62. } // namespace android