Loading libs/gui/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -104,6 +104,7 @@ cc_library_shared { "IGraphicBufferConsumer.cpp", "IGraphicBufferProducer.cpp", "IProducerListener.cpp", "IRegionSamplingListener.cpp", "ISurfaceComposer.cpp", "ISurfaceComposerClient.cpp", "ITransactionCompletedListener.cpp", Loading libs/gui/IRegionSamplingListener.cpp 0 → 100644 +64 −0 Original line number Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "IRegionSamplingListener" //#define LOG_NDEBUG 0 #include <gui/IRegionSamplingListener.h> namespace android { namespace { // Anonymous enum class Tag : uint32_t { ON_SAMPLE_COLLECTED = IBinder::FIRST_CALL_TRANSACTION, LAST = ON_SAMPLE_COLLECTED, }; } // Anonymous namespace class BpRegionSamplingListener : public SafeBpInterface<IRegionSamplingListener> { public: explicit BpRegionSamplingListener(const sp<IBinder>& impl) : SafeBpInterface<IRegionSamplingListener>(impl, "BpRegionSamplingListener") {} ~BpRegionSamplingListener() override; void onSampleCollected(float medianLuma) override { callRemoteAsync<decltype( &IRegionSamplingListener::onSampleCollected)>(Tag::ON_SAMPLE_COLLECTED, medianLuma); } }; // Out-of-line virtual method definitions to trigger vtable emission in this translation unit (see // clang warning -Wweak-vtables) BpRegionSamplingListener::~BpRegionSamplingListener() = default; IMPLEMENT_META_INTERFACE(RegionSamplingListener, "android.gui.IRegionSamplingListener"); status_t BnRegionSamplingListener::onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) { return BBinder::onTransact(code, data, reply, flags); } auto tag = static_cast<Tag>(code); switch (tag) { case Tag::ON_SAMPLE_COLLECTED: return callLocalAsync(data, reply, &IRegionSamplingListener::onSampleCollected); } } } // namespace android libs/gui/ISurfaceComposer.cpp +84 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <gui/IDisplayEventConnection.h> #include <gui/IGraphicBufferProducer.h> #include <gui/IRegionSamplingListener.h> #include <gui/ISurfaceComposer.h> #include <gui/ISurfaceComposerClient.h> #include <gui/LayerDebugInfo.h> Loading Loading @@ -754,6 +755,57 @@ public: error = reply.readBool(outIsWideColorDisplay); return error; } virtual status_t addRegionSamplingListener(const Rect& samplingArea, const sp<IBinder>& stopLayerHandle, const sp<IRegionSamplingListener>& listener) { Parcel data, reply; status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to write interface token"); return error; } error = data.write(samplingArea); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to write sampling area"); return error; } error = data.writeStrongBinder(stopLayerHandle); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to write stop layer handle"); return error; } error = data.writeStrongBinder(IInterface::asBinder(listener)); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to write listener"); return error; } error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to transact"); } return error; } virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { Parcel data, reply; status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to write interface token"); return error; } error = data.writeStrongBinder(IInterface::asBinder(listener)); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to write listener"); return error; } error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data, &reply); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to transact"); } return error; } }; // Out-of-line virtual method definition to trigger vtable emission in this Loading Loading @@ -1233,6 +1285,38 @@ status_t BnSurfaceComposer::onTransact( CHECK_INTERFACE(ISurfaceComposer, data, reply); return reply->writeUint64Vector(getPhysicalDisplayIds()); } case ADD_REGION_SAMPLING_LISTENER: { CHECK_INTERFACE(ISurfaceComposer, data, reply); Rect samplingArea; status_t result = data.read(samplingArea); if (result != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to read sampling area"); return result; } sp<IBinder> stopLayerHandle; result = data.readNullableStrongBinder(&stopLayerHandle); if (result != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to read stop layer handle"); return result; } sp<IRegionSamplingListener> listener; result = data.readNullableStrongBinder(&listener); if (result != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to read listener"); return result; } return addRegionSamplingListener(samplingArea, stopLayerHandle, listener); } case REMOVE_REGION_SAMPLING_LISTENER: { CHECK_INTERFACE(ISurfaceComposer, data, reply); sp<IRegionSamplingListener> listener; status_t result = data.readNullableStrongBinder(&listener); if (result != NO_ERROR) { ALOGE("removeRegionSamplingListener: Failed to read listener"); return result; } return removeRegionSamplingListener(listener); } default: { return BBinder::onTransact(code, data, reply, flags); } Loading libs/gui/include/gui/IRegionSamplingListener.h 0 → 100644 +43 −0 Original line number Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <cstdint> #include <vector> #include <binder/IInterface.h> #include <binder/SafeInterface.h> namespace android { class IRegionSamplingListener : public IInterface { public: DECLARE_META_INTERFACE(RegionSamplingListener) virtual void onSampleCollected(float medianLuma) = 0; }; class BnRegionSamplingListener : public SafeBnInterface<IRegionSamplingListener> { public: BnRegionSamplingListener() : SafeBnInterface<IRegionSamplingListener>("BnRegionSamplingListener") {} status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0) override; }; } // namespace android libs/gui/include/gui/ISurfaceComposer.h +23 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ class HdrCapabilities; class IDisplayEventConnection; class IGraphicBufferProducer; class ISurfaceComposerClient; class IRegionSamplingListener; class Rect; enum class FrameEvent; Loading Loading @@ -338,6 +339,26 @@ public: */ virtual status_t isWideColorDisplay(const sp<IBinder>& token, bool* outIsWideColorDisplay) const = 0; /* Registers a listener to stream median luma updates from SurfaceFlinger. * * The sampling area is bounded by both samplingArea and the given stopLayerHandle * (i.e., only layers behind the stop layer will be captured and sampled). * * Multiple listeners may be provided so long as they have independent listeners. * If multiple listeners are provided, the effective sampling region for each listener will * be bounded by whichever stop layer has a lower Z value. * * Requires the same permissions as captureLayers and captureScreen. */ virtual status_t addRegionSamplingListener(const Rect& samplingArea, const sp<IBinder>& stopLayerHandle, const sp<IRegionSamplingListener>& listener) = 0; /* * Removes a listener that was streaming median luma updates from SurfaceFlinger. */ virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) = 0; }; // ---------------------------------------------------------------------------- Loading Loading @@ -383,6 +404,8 @@ public: IS_WIDE_COLOR_DISPLAY, GET_DISPLAY_NATIVE_PRIMARIES, GET_PHYSICAL_DISPLAY_IDS, ADD_REGION_SAMPLING_LISTENER, REMOVE_REGION_SAMPLING_LISTENER, // Always append new enum to the end. }; Loading Loading
libs/gui/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -104,6 +104,7 @@ cc_library_shared { "IGraphicBufferConsumer.cpp", "IGraphicBufferProducer.cpp", "IProducerListener.cpp", "IRegionSamplingListener.cpp", "ISurfaceComposer.cpp", "ISurfaceComposerClient.cpp", "ITransactionCompletedListener.cpp", Loading
libs/gui/IRegionSamplingListener.cpp 0 → 100644 +64 −0 Original line number Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "IRegionSamplingListener" //#define LOG_NDEBUG 0 #include <gui/IRegionSamplingListener.h> namespace android { namespace { // Anonymous enum class Tag : uint32_t { ON_SAMPLE_COLLECTED = IBinder::FIRST_CALL_TRANSACTION, LAST = ON_SAMPLE_COLLECTED, }; } // Anonymous namespace class BpRegionSamplingListener : public SafeBpInterface<IRegionSamplingListener> { public: explicit BpRegionSamplingListener(const sp<IBinder>& impl) : SafeBpInterface<IRegionSamplingListener>(impl, "BpRegionSamplingListener") {} ~BpRegionSamplingListener() override; void onSampleCollected(float medianLuma) override { callRemoteAsync<decltype( &IRegionSamplingListener::onSampleCollected)>(Tag::ON_SAMPLE_COLLECTED, medianLuma); } }; // Out-of-line virtual method definitions to trigger vtable emission in this translation unit (see // clang warning -Wweak-vtables) BpRegionSamplingListener::~BpRegionSamplingListener() = default; IMPLEMENT_META_INTERFACE(RegionSamplingListener, "android.gui.IRegionSamplingListener"); status_t BnRegionSamplingListener::onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) { return BBinder::onTransact(code, data, reply, flags); } auto tag = static_cast<Tag>(code); switch (tag) { case Tag::ON_SAMPLE_COLLECTED: return callLocalAsync(data, reply, &IRegionSamplingListener::onSampleCollected); } } } // namespace android
libs/gui/ISurfaceComposer.cpp +84 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <gui/IDisplayEventConnection.h> #include <gui/IGraphicBufferProducer.h> #include <gui/IRegionSamplingListener.h> #include <gui/ISurfaceComposer.h> #include <gui/ISurfaceComposerClient.h> #include <gui/LayerDebugInfo.h> Loading Loading @@ -754,6 +755,57 @@ public: error = reply.readBool(outIsWideColorDisplay); return error; } virtual status_t addRegionSamplingListener(const Rect& samplingArea, const sp<IBinder>& stopLayerHandle, const sp<IRegionSamplingListener>& listener) { Parcel data, reply; status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to write interface token"); return error; } error = data.write(samplingArea); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to write sampling area"); return error; } error = data.writeStrongBinder(stopLayerHandle); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to write stop layer handle"); return error; } error = data.writeStrongBinder(IInterface::asBinder(listener)); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to write listener"); return error; } error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to transact"); } return error; } virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) { Parcel data, reply; status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to write interface token"); return error; } error = data.writeStrongBinder(IInterface::asBinder(listener)); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to write listener"); return error; } error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data, &reply); if (error != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to transact"); } return error; } }; // Out-of-line virtual method definition to trigger vtable emission in this Loading Loading @@ -1233,6 +1285,38 @@ status_t BnSurfaceComposer::onTransact( CHECK_INTERFACE(ISurfaceComposer, data, reply); return reply->writeUint64Vector(getPhysicalDisplayIds()); } case ADD_REGION_SAMPLING_LISTENER: { CHECK_INTERFACE(ISurfaceComposer, data, reply); Rect samplingArea; status_t result = data.read(samplingArea); if (result != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to read sampling area"); return result; } sp<IBinder> stopLayerHandle; result = data.readNullableStrongBinder(&stopLayerHandle); if (result != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to read stop layer handle"); return result; } sp<IRegionSamplingListener> listener; result = data.readNullableStrongBinder(&listener); if (result != NO_ERROR) { ALOGE("addRegionSamplingListener: Failed to read listener"); return result; } return addRegionSamplingListener(samplingArea, stopLayerHandle, listener); } case REMOVE_REGION_SAMPLING_LISTENER: { CHECK_INTERFACE(ISurfaceComposer, data, reply); sp<IRegionSamplingListener> listener; status_t result = data.readNullableStrongBinder(&listener); if (result != NO_ERROR) { ALOGE("removeRegionSamplingListener: Failed to read listener"); return result; } return removeRegionSamplingListener(listener); } default: { return BBinder::onTransact(code, data, reply, flags); } Loading
libs/gui/include/gui/IRegionSamplingListener.h 0 → 100644 +43 −0 Original line number Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <cstdint> #include <vector> #include <binder/IInterface.h> #include <binder/SafeInterface.h> namespace android { class IRegionSamplingListener : public IInterface { public: DECLARE_META_INTERFACE(RegionSamplingListener) virtual void onSampleCollected(float medianLuma) = 0; }; class BnRegionSamplingListener : public SafeBnInterface<IRegionSamplingListener> { public: BnRegionSamplingListener() : SafeBnInterface<IRegionSamplingListener>("BnRegionSamplingListener") {} status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0) override; }; } // namespace android
libs/gui/include/gui/ISurfaceComposer.h +23 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ class HdrCapabilities; class IDisplayEventConnection; class IGraphicBufferProducer; class ISurfaceComposerClient; class IRegionSamplingListener; class Rect; enum class FrameEvent; Loading Loading @@ -338,6 +339,26 @@ public: */ virtual status_t isWideColorDisplay(const sp<IBinder>& token, bool* outIsWideColorDisplay) const = 0; /* Registers a listener to stream median luma updates from SurfaceFlinger. * * The sampling area is bounded by both samplingArea and the given stopLayerHandle * (i.e., only layers behind the stop layer will be captured and sampled). * * Multiple listeners may be provided so long as they have independent listeners. * If multiple listeners are provided, the effective sampling region for each listener will * be bounded by whichever stop layer has a lower Z value. * * Requires the same permissions as captureLayers and captureScreen. */ virtual status_t addRegionSamplingListener(const Rect& samplingArea, const sp<IBinder>& stopLayerHandle, const sp<IRegionSamplingListener>& listener) = 0; /* * Removes a listener that was streaming median luma updates from SurfaceFlinger. */ virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) = 0; }; // ---------------------------------------------------------------------------- Loading Loading @@ -383,6 +404,8 @@ public: IS_WIDE_COLOR_DISPLAY, GET_DISPLAY_NATIVE_PRIMARIES, GET_PHYSICAL_DISPLAY_IDS, ADD_REGION_SAMPLING_LISTENER, REMOVE_REGION_SAMPLING_LISTENER, // Always append new enum to the end. }; Loading