DisplayEventReceiver.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C) 2011 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 <string.h>
  17. #include <utils/Errors.h>
  18. #include <gui/BitTube.h>
  19. #include <gui/DisplayEventReceiver.h>
  20. #include <gui/IDisplayEventConnection.h>
  21. #include <gui/ISurfaceComposer.h>
  22. #include <private/gui/ComposerService.h>
  23. // ---------------------------------------------------------------------------
  24. namespace android {
  25. // ---------------------------------------------------------------------------
  26. DisplayEventReceiver::DisplayEventReceiver() {
  27. sp<ISurfaceComposer> sf(ComposerService::getComposerService());
  28. if (sf != NULL) {
  29. mEventConnection = sf->createDisplayEventConnection();
  30. if (mEventConnection != NULL) {
  31. mDataChannel = mEventConnection->getDataChannel();
  32. }
  33. }
  34. }
  35. DisplayEventReceiver::~DisplayEventReceiver() {
  36. }
  37. status_t DisplayEventReceiver::initCheck() const {
  38. if (mDataChannel != NULL)
  39. return NO_ERROR;
  40. return NO_INIT;
  41. }
  42. int DisplayEventReceiver::getFd() const {
  43. if (mDataChannel == NULL)
  44. return NO_INIT;
  45. return mDataChannel->getFd();
  46. }
  47. status_t DisplayEventReceiver::setVsyncRate(uint32_t count) {
  48. if (int32_t(count) < 0)
  49. return BAD_VALUE;
  50. if (mEventConnection != NULL) {
  51. mEventConnection->setVsyncRate(count);
  52. return NO_ERROR;
  53. }
  54. return NO_INIT;
  55. }
  56. status_t DisplayEventReceiver::requestNextVsync() {
  57. if (mEventConnection != NULL) {
  58. mEventConnection->requestNextVsync();
  59. return NO_ERROR;
  60. }
  61. return NO_INIT;
  62. }
  63. ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events,
  64. size_t count) {
  65. return DisplayEventReceiver::getEvents(mDataChannel, events, count);
  66. }
  67. ssize_t DisplayEventReceiver::getEvents(const sp<BitTube>& dataChannel,
  68. Event* events, size_t count)
  69. {
  70. return BitTube::recvObjects(dataChannel, events, count);
  71. }
  72. ssize_t DisplayEventReceiver::sendEvents(const sp<BitTube>& dataChannel,
  73. Event const* events, size_t count)
  74. {
  75. return BitTube::sendObjects(dataChannel, events, count);
  76. }
  77. // ---------------------------------------------------------------------------
  78. }; // namespace android