IDisplayEventConnection.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 <stdint.h>
  17. #include <sys/types.h>
  18. #include <utils/Errors.h>
  19. #include <utils/RefBase.h>
  20. #include <utils/Timers.h>
  21. #include <binder/Parcel.h>
  22. #include <binder/IInterface.h>
  23. #include <gui/IDisplayEventConnection.h>
  24. #include <gui/BitTube.h>
  25. namespace android {
  26. // ----------------------------------------------------------------------------
  27. enum {
  28. GET_DATA_CHANNEL = IBinder::FIRST_CALL_TRANSACTION,
  29. SET_VSYNC_RATE,
  30. REQUEST_NEXT_VSYNC
  31. };
  32. class BpDisplayEventConnection : public BpInterface<IDisplayEventConnection>
  33. {
  34. public:
  35. BpDisplayEventConnection(const sp<IBinder>& impl)
  36. : BpInterface<IDisplayEventConnection>(impl)
  37. {
  38. }
  39. virtual ~BpDisplayEventConnection();
  40. virtual sp<BitTube> getDataChannel() const
  41. {
  42. Parcel data, reply;
  43. data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
  44. remote()->transact(GET_DATA_CHANNEL, data, &reply);
  45. return new BitTube(reply);
  46. }
  47. virtual void setVsyncRate(uint32_t count) {
  48. Parcel data, reply;
  49. data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
  50. data.writeUint32(count);
  51. remote()->transact(SET_VSYNC_RATE, data, &reply);
  52. }
  53. virtual void requestNextVsync() {
  54. Parcel data, reply;
  55. data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
  56. remote()->transact(REQUEST_NEXT_VSYNC, data, &reply, IBinder::FLAG_ONEWAY);
  57. }
  58. };
  59. // Out-of-line virtual method definition to trigger vtable emission in this
  60. // translation unit (see clang warning -Wweak-vtables)
  61. BpDisplayEventConnection::~BpDisplayEventConnection() {}
  62. IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection");
  63. // ----------------------------------------------------------------------------
  64. status_t BnDisplayEventConnection::onTransact(
  65. uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
  66. {
  67. switch(code) {
  68. case GET_DATA_CHANNEL: {
  69. CHECK_INTERFACE(IDisplayEventConnection, data, reply);
  70. sp<BitTube> channel(getDataChannel());
  71. channel->writeToParcel(reply);
  72. return NO_ERROR;
  73. }
  74. case SET_VSYNC_RATE: {
  75. CHECK_INTERFACE(IDisplayEventConnection, data, reply);
  76. setVsyncRate(data.readUint32());
  77. return NO_ERROR;
  78. }
  79. case REQUEST_NEXT_VSYNC: {
  80. CHECK_INTERFACE(IDisplayEventConnection, data, reply);
  81. requestNextVsync();
  82. return NO_ERROR;
  83. }
  84. }
  85. return BBinder::onTransact(code, data, reply, flags);
  86. }
  87. // ----------------------------------------------------------------------------
  88. }; // namespace android