ISurfaceComposerClient.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C) 2007 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. // tag as surfaceflinger
  17. #define LOG_TAG "SurfaceFlinger"
  18. #include <stdio.h>
  19. #include <stdint.h>
  20. #include <sys/types.h>
  21. #include <binder/Parcel.h>
  22. #include <binder/IMemory.h>
  23. #include <binder/IPCThreadState.h>
  24. #include <binder/IServiceManager.h>
  25. #include <ui/Point.h>
  26. #include <ui/Rect.h>
  27. #include <gui/IGraphicBufferProducer.h>
  28. #include <gui/ISurfaceComposerClient.h>
  29. #include <private/gui/LayerState.h>
  30. // ---------------------------------------------------------------------------
  31. namespace android {
  32. enum {
  33. CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
  34. DESTROY_SURFACE,
  35. CLEAR_LAYER_FRAME_STATS,
  36. GET_LAYER_FRAME_STATS
  37. };
  38. class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
  39. {
  40. public:
  41. BpSurfaceComposerClient(const sp<IBinder>& impl)
  42. : BpInterface<ISurfaceComposerClient>(impl) {
  43. }
  44. virtual ~BpSurfaceComposerClient();
  45. virtual status_t createSurface(const String8& name, uint32_t width,
  46. uint32_t height, PixelFormat format, uint32_t flags,
  47. sp<IBinder>* handle,
  48. sp<IGraphicBufferProducer>* gbp) {
  49. Parcel data, reply;
  50. data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
  51. data.writeString8(name);
  52. data.writeUint32(width);
  53. data.writeUint32(height);
  54. data.writeInt32(static_cast<int32_t>(format));
  55. data.writeUint32(flags);
  56. remote()->transact(CREATE_SURFACE, data, &reply);
  57. *handle = reply.readStrongBinder();
  58. *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
  59. return reply.readInt32();
  60. }
  61. virtual status_t destroySurface(const sp<IBinder>& handle) {
  62. Parcel data, reply;
  63. data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
  64. data.writeStrongBinder(handle);
  65. remote()->transact(DESTROY_SURFACE, data, &reply);
  66. return reply.readInt32();
  67. }
  68. virtual status_t clearLayerFrameStats(const sp<IBinder>& handle) const {
  69. Parcel data, reply;
  70. data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
  71. data.writeStrongBinder(handle);
  72. remote()->transact(CLEAR_LAYER_FRAME_STATS, data, &reply);
  73. return reply.readInt32();
  74. }
  75. virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const {
  76. Parcel data, reply;
  77. data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
  78. data.writeStrongBinder(handle);
  79. remote()->transact(GET_LAYER_FRAME_STATS, data, &reply);
  80. reply.read(*outStats);
  81. return reply.readInt32();
  82. }
  83. };
  84. // Out-of-line virtual method definition to trigger vtable emission in this
  85. // translation unit (see clang warning -Wweak-vtables)
  86. BpSurfaceComposerClient::~BpSurfaceComposerClient() {}
  87. IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
  88. // ----------------------------------------------------------------------
  89. status_t BnSurfaceComposerClient::onTransact(
  90. uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
  91. {
  92. switch(code) {
  93. case CREATE_SURFACE: {
  94. CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
  95. String8 name = data.readString8();
  96. uint32_t width = data.readUint32();
  97. uint32_t height = data.readUint32();
  98. PixelFormat format = static_cast<PixelFormat>(data.readInt32());
  99. uint32_t createFlags = data.readUint32();
  100. sp<IBinder> handle;
  101. sp<IGraphicBufferProducer> gbp;
  102. status_t result = createSurface(name, width, height, format,
  103. createFlags, &handle, &gbp);
  104. reply->writeStrongBinder(handle);
  105. reply->writeStrongBinder(IInterface::asBinder(gbp));
  106. reply->writeInt32(result);
  107. return NO_ERROR;
  108. }
  109. case DESTROY_SURFACE: {
  110. CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
  111. reply->writeInt32(destroySurface( data.readStrongBinder() ) );
  112. return NO_ERROR;
  113. }
  114. case CLEAR_LAYER_FRAME_STATS: {
  115. CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
  116. sp<IBinder> handle = data.readStrongBinder();
  117. status_t result = clearLayerFrameStats(handle);
  118. reply->writeInt32(result);
  119. return NO_ERROR;
  120. }
  121. case GET_LAYER_FRAME_STATS: {
  122. CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
  123. sp<IBinder> handle = data.readStrongBinder();
  124. FrameStats stats;
  125. status_t result = getLayerFrameStats(handle, &stats);
  126. reply->write(stats);
  127. reply->writeInt32(result);
  128. return NO_ERROR;
  129. }
  130. default:
  131. return BBinder::onTransact(code, data, reply, flags);
  132. }
  133. }
  134. }; // namespace android