NativeWindow.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright 2019 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 "compositionengine/mock/NativeWindow.h"
  17. #include <log/log.h>
  18. namespace android::compositionengine::mock {
  19. static int forwardSetSwapInterval(ANativeWindow* window, int interval) {
  20. return static_cast<NativeWindow*>(window)->setSwapInterval(interval);
  21. }
  22. static int forwardDequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd) {
  23. return static_cast<NativeWindow*>(window)->dequeueBuffer(buffer, fenceFd);
  24. }
  25. static int forwardCancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) {
  26. return static_cast<NativeWindow*>(window)->cancelBuffer(buffer, fenceFd);
  27. }
  28. static int forwardQueueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) {
  29. return static_cast<NativeWindow*>(window)->queueBuffer(buffer, fenceFd);
  30. }
  31. static int forwardQuery(const ANativeWindow* window, int what, int* value) {
  32. return static_cast<const NativeWindow*>(window)->query(what, value);
  33. }
  34. static int forwardPerform(ANativeWindow* window, int operation, ...) {
  35. va_list args;
  36. va_start(args, operation);
  37. int result = NO_ERROR;
  38. switch (operation) {
  39. case NATIVE_WINDOW_API_CONNECT: {
  40. int api = va_arg(args, int);
  41. result = static_cast<NativeWindow*>(window)->connect(api);
  42. break;
  43. }
  44. case NATIVE_WINDOW_SET_BUFFERS_FORMAT: {
  45. PixelFormat format = va_arg(args, PixelFormat);
  46. result = static_cast<NativeWindow*>(window)->setBuffersFormat(format);
  47. break;
  48. }
  49. case NATIVE_WINDOW_SET_BUFFERS_DATASPACE: {
  50. ui::Dataspace dataspace = static_cast<ui::Dataspace>(va_arg(args, int));
  51. result = static_cast<NativeWindow*>(window)->setBuffersDataSpace(dataspace);
  52. break;
  53. }
  54. case NATIVE_WINDOW_SET_USAGE: {
  55. // Note: Intentionally widens usage from 32 to 64 bits so we
  56. // just have one implementation.
  57. uint64_t usage = va_arg(args, uint32_t);
  58. result = static_cast<NativeWindow*>(window)->setUsage(usage);
  59. break;
  60. }
  61. case NATIVE_WINDOW_SET_USAGE64: {
  62. uint64_t usage = va_arg(args, uint64_t);
  63. result = static_cast<NativeWindow*>(window)->setUsage(usage);
  64. break;
  65. }
  66. case NATIVE_WINDOW_API_DISCONNECT: {
  67. int api = va_arg(args, int);
  68. result = static_cast<NativeWindow*>(window)->disconnect(api);
  69. break;
  70. }
  71. default:
  72. LOG_ALWAYS_FATAL("Unexpected operation %d", operation);
  73. break;
  74. }
  75. va_end(args);
  76. return result;
  77. }
  78. static int forwardDequeueBufferDeprecated(ANativeWindow* window, ANativeWindowBuffer** buffer) {
  79. int ignoredFenceFd = -1;
  80. return static_cast<NativeWindow*>(window)->dequeueBuffer(buffer, &ignoredFenceFd);
  81. }
  82. static int forwardCancelBufferDeprecated(ANativeWindow* window, ANativeWindowBuffer* buffer) {
  83. return static_cast<NativeWindow*>(window)->cancelBuffer(buffer, -1);
  84. }
  85. static int forwardLockBufferDeprecated(ANativeWindow* window, ANativeWindowBuffer* buffer) {
  86. return static_cast<NativeWindow*>(window)->lockBuffer_DEPRECATED(buffer);
  87. }
  88. static int forwardQueueBufferDeprecated(ANativeWindow* window, ANativeWindowBuffer* buffer) {
  89. return static_cast<NativeWindow*>(window)->queueBuffer(buffer, -1);
  90. }
  91. NativeWindow::NativeWindow() {
  92. ANativeWindow::setSwapInterval = &forwardSetSwapInterval;
  93. ANativeWindow::dequeueBuffer = &forwardDequeueBuffer;
  94. ANativeWindow::cancelBuffer = &forwardCancelBuffer;
  95. ANativeWindow::queueBuffer = &forwardQueueBuffer;
  96. ANativeWindow::query = &forwardQuery;
  97. ANativeWindow::perform = &forwardPerform;
  98. ANativeWindow::dequeueBuffer_DEPRECATED = &forwardDequeueBufferDeprecated;
  99. ANativeWindow::cancelBuffer_DEPRECATED = &forwardCancelBufferDeprecated;
  100. ANativeWindow::lockBuffer_DEPRECATED = &forwardLockBufferDeprecated;
  101. ANativeWindow::queueBuffer_DEPRECATED = &forwardQueueBufferDeprecated;
  102. }
  103. NativeWindow::~NativeWindow() = default;
  104. } // namespace android::compositionengine::mock