1 /*
2 * Copyright 2021 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
17 #undef LOG_TAG
18 #define LOG_TAG "HdrLayerInfoReporter"
19 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
20
21 #include <utils/Trace.h>
22
23 #include "HdrLayerInfoReporter.h"
24
25 namespace android {
26
dispatchHdrLayerInfo(const HdrLayerInfo & info)27 void HdrLayerInfoReporter::dispatchHdrLayerInfo(const HdrLayerInfo& info) {
28 ATRACE_CALL();
29 std::vector<sp<gui::IHdrLayerInfoListener>> toInvoke;
30 {
31 std::scoped_lock lock(mMutex);
32 toInvoke.reserve(mListeners.size());
33 for (auto& [key, it] : mListeners) {
34 if (it.lastInfo != info) {
35 it.lastInfo = info;
36 toInvoke.push_back(it.listener);
37 }
38 }
39 }
40
41 for (const auto& listener : toInvoke) {
42 ATRACE_NAME("invoking onHdrLayerInfoChanged");
43 listener->onHdrLayerInfoChanged(info.numberOfHdrLayers, info.maxW, info.maxH, info.flags,
44 info.maxDesiredHdrSdrRatio);
45 }
46 }
47
binderDied(const wp<IBinder> & who)48 void HdrLayerInfoReporter::binderDied(const wp<IBinder>& who) {
49 std::scoped_lock lock(mMutex);
50 mListeners.erase(who);
51 }
52
addListener(const sp<gui::IHdrLayerInfoListener> & listener)53 void HdrLayerInfoReporter::addListener(const sp<gui::IHdrLayerInfoListener>& listener) {
54 sp<IBinder> asBinder = IInterface::asBinder(listener);
55 asBinder->linkToDeath(sp<DeathRecipient>::fromExisting(this));
56 std::lock_guard lock(mMutex);
57 mListeners.emplace(wp<IBinder>(asBinder), TrackedListener{listener, HdrLayerInfo{}});
58 }
59
removeListener(const sp<gui::IHdrLayerInfoListener> & listener)60 void HdrLayerInfoReporter::removeListener(const sp<gui::IHdrLayerInfoListener>& listener) {
61 std::lock_guard lock(mMutex);
62 mListeners.erase(wp<IBinder>(IInterface::asBinder(listener)));
63 }
64
65 } // namespace android