blob: 9eefbe463dde0f08e407359af2d53a184ad2b83a [file] [log] [blame]
John Reck88270902021-03-18 11:27:35 -04001/*
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
25namespace android {
26
27void 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");
Alec Mouric68c61a2023-02-09 17:35:36 +000043 listener->onHdrLayerInfoChanged(info.numberOfHdrLayers, info.maxW, info.maxH, info.flags,
44 info.maxDesiredHdrSdrRatio);
John Reck88270902021-03-18 11:27:35 -040045 }
46}
47
48void HdrLayerInfoReporter::binderDied(const wp<IBinder>& who) {
49 std::scoped_lock lock(mMutex);
50 mListeners.erase(who);
51}
52
53void HdrLayerInfoReporter::addListener(const sp<gui::IHdrLayerInfoListener>& listener) {
54 sp<IBinder> asBinder = IInterface::asBinder(listener);
Ady Abrahamd11bade2022-08-01 16:18:03 -070055 asBinder->linkToDeath(sp<DeathRecipient>::fromExisting(this));
John Reck88270902021-03-18 11:27:35 -040056 std::lock_guard lock(mMutex);
57 mListeners.emplace(wp<IBinder>(asBinder), TrackedListener{listener, HdrLayerInfo{}});
58}
59
60void 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