ISurfaceComposerClient.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 <gui/ISurfaceComposerClient.h>
  19. #include <gui/IGraphicBufferProducer.h>
  20. #include <binder/SafeInterface.h>
  21. #include <ui/FrameStats.h>
  22. #include <cutils/properties.h>
  23. namespace android {
  24. namespace { // Anonymous
  25. enum class Tag : uint32_t {
  26. CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
  27. CREATE_WITH_SURFACE_PARENT,
  28. CLEAR_LAYER_FRAME_STATS,
  29. GET_LAYER_FRAME_STATS,
  30. LAST = GET_LAYER_FRAME_STATS,
  31. };
  32. } // Anonymous namespace
  33. class BpSurfaceComposerClient : public SafeBpInterface<ISurfaceComposerClient> {
  34. public:
  35. explicit BpSurfaceComposerClient(const sp<IBinder>& impl)
  36. : SafeBpInterface<ISurfaceComposerClient>(impl, "BpSurfaceComposerClient") {}
  37. ~BpSurfaceComposerClient() override;
  38. status_t createSurface(const String8& name, uint32_t width, uint32_t height, PixelFormat format,
  39. uint32_t flags, const sp<IBinder>& parent, LayerMetadata metadata,
  40. sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp) override {
  41. char systemname[PROPERTY_VALUE_MAX]={0};
  42. property_get("persist.sys.vm.name", systemname, "");
  43. Parcel data, reply;
  44. data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
  45. data.writeString8(name);
  46. data.writeString8(String8(systemname));
  47. data.writeUint32(width);
  48. data.writeUint32(height);
  49. data.writeInt32(static_cast<int32_t>(format));
  50. data.writeUint32(flags);
  51. data.writeStrongBinder(parent);
  52. metadata.writeToParcel(&data);
  53. remote()->transact(static_cast<uint32_t>(Tag::CREATE_SURFACE), data, &reply);
  54. *handle = reply.readStrongBinder();
  55. *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
  56. return reply.readInt32();
  57. }
  58. status_t createWithSurfaceParent(const String8& name, uint32_t width, uint32_t height,
  59. PixelFormat format, uint32_t flags,
  60. const sp<IGraphicBufferProducer>& parent,
  61. LayerMetadata metadata, sp<IBinder>* handle,
  62. sp<IGraphicBufferProducer>* gbp) override {
  63. char systemname[PROPERTY_VALUE_MAX]={0};
  64. property_get("persist.sys.vm.name", systemname, "");
  65. Parcel data, reply;
  66. data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
  67. data.writeString8(name);
  68. data.writeString8(String8(systemname));
  69. data.writeUint32(width);
  70. data.writeUint32(height);
  71. data.writeInt32(static_cast<int32_t>(format));
  72. data.writeUint32(flags);
  73. data.writeStrongBinder(IInterface::asBinder(parent));
  74. metadata.writeToParcel(&data);
  75. remote()->transact(static_cast<uint32_t>(Tag::CREATE_WITH_SURFACE_PARENT), data, &reply);
  76. *handle = reply.readStrongBinder();
  77. *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
  78. return reply.readInt32();
  79. }
  80. status_t clearLayerFrameStats(const sp<IBinder>& handle) const override {
  81. return callRemote<decltype(
  82. &ISurfaceComposerClient::clearLayerFrameStats)>(Tag::CLEAR_LAYER_FRAME_STATS,
  83. handle);
  84. }
  85. status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const override {
  86. return callRemote<decltype(
  87. &ISurfaceComposerClient::getLayerFrameStats)>(Tag::GET_LAYER_FRAME_STATS, handle,
  88. outStats);
  89. }
  90. };
  91. // Out-of-line virtual method definition to trigger vtable emission in this
  92. // translation unit (see clang warning -Wweak-vtables)
  93. BpSurfaceComposerClient::~BpSurfaceComposerClient() {}
  94. IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
  95. // ----------------------------------------------------------------------
  96. status_t BnSurfaceComposerClient::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
  97. uint32_t flags) {
  98. if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) {
  99. return BBinder::onTransact(code, data, reply, flags);
  100. }
  101. auto tag = static_cast<Tag>(code);
  102. switch (tag) {
  103. case Tag::CREATE_SURFACE:{
  104. CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
  105. String8 name = data.readString8();
  106. String8 systemname = data.readString8();
  107. uint32_t width = data.readUint32();
  108. uint32_t height = data.readUint32();
  109. PixelFormat format = static_cast<PixelFormat>(data.readInt32());
  110. uint32_t createFlags = data.readUint32();
  111. sp<IBinder> parent = data.readStrongBinder();
  112. LayerMetadata metadata;
  113. metadata.readFromParcel(&data);
  114. sp<IBinder> handle;
  115. sp<IGraphicBufferProducer> gbp;
  116. status_t result = createSurfaceX(name, systemname, width, height, format,
  117. createFlags, parent, metadata, &handle, &gbp);
  118. reply->writeStrongBinder(handle);
  119. reply->writeStrongBinder(IInterface::asBinder(gbp));
  120. reply->writeInt32(result);
  121. return NO_ERROR;
  122. }
  123. case Tag::CREATE_WITH_SURFACE_PARENT:{
  124. CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
  125. String8 name = data.readString8();
  126. String8 systemname = data.readString8();
  127. uint32_t width = data.readUint32();
  128. uint32_t height = data.readUint32();
  129. PixelFormat format = static_cast<PixelFormat>(data.readInt32());
  130. uint32_t createFlags = data.readUint32();
  131. sp<IGraphicBufferProducer> parent = interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
  132. LayerMetadata metadata;
  133. metadata.readFromParcel(&data);
  134. sp<IBinder> handle;
  135. sp<IGraphicBufferProducer> gbp;
  136. status_t result = createWithSurfaceParentX(name, systemname, width, height, format,
  137. createFlags, parent, metadata, &handle, &gbp);
  138. reply->writeStrongBinder(handle);
  139. reply->writeStrongBinder(IInterface::asBinder(gbp));
  140. reply->writeInt32(result);
  141. return NO_ERROR;
  142. }
  143. case Tag::CLEAR_LAYER_FRAME_STATS:
  144. return callLocal(data, reply, &ISurfaceComposerClient::clearLayerFrameStats);
  145. case Tag::GET_LAYER_FRAME_STATS:
  146. return callLocal(data, reply, &ISurfaceComposerClient::getLayerFrameStats);
  147. }
  148. }
  149. } // namespace android