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 }
45 }
46
binderDied(const wp<IBinder> & who)47 void HdrLayerInfoReporter::binderDied(const wp<IBinder>& who) {
48 std::scoped_lock lock(mMutex);
49 mListeners.erase(who);
50 }
51
addListener(const sp<gui::IHdrLayerInfoListener> & listener)52 void HdrLayerInfoReporter::addListener(const sp<gui::IHdrLayerInfoListener>& listener) {
53 sp<IBinder> asBinder = IInterface::asBinder(listener);
54 asBinder->linkToDeath(this);
55 std::lock_guard lock(mMutex);
56 mListeners.emplace(wp<IBinder>(asBinder), TrackedListener{listener, HdrLayerInfo{}});
57 }
58
removeListener(const sp<gui::IHdrLayerInfoListener> & listener)59 void HdrLayerInfoReporter::removeListener(const sp<gui::IHdrLayerInfoListener>& listener) {
60 std::lock_guard lock(mMutex);
61 mListeners.erase(wp<IBinder>(IInterface::asBinder(listener)));
62 }
63
64 } // namespace android