blob: c88554ee523cd8bab4c957ab6abf41c24fc6da5a [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");
43 listener->onHdrLayerInfoChanged(info.numberOfHdrLayers, info.maxW, info.maxH, info.flags);
44 }
45}
46
47void HdrLayerInfoReporter::binderDied(const wp<IBinder>& who) {
48 std::scoped_lock lock(mMutex);
49 mListeners.erase(who);
50}
51
52void HdrLayerInfoReporter::addListener(const sp<gui::IHdrLayerInfoListener>& listener) {
53 sp<IBinder> asBinder = IInterface::asBinder(listener);
Ady Abrahamd11bade2022-08-01 16:18:03 -070054 asBinder->linkToDeath(sp<DeathRecipient>::fromExisting(this));
John Reck88270902021-03-18 11:27:35 -040055 std::lock_guard lock(mMutex);
56 mListeners.emplace(wp<IBinder>(asBinder), TrackedListener{listener, HdrLayerInfo{}});
57}
58
59void 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