1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2007 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker *
4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker *
8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker *
10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker */
16*38e8c45fSAndroid Build Coastguard Worker
17*38e8c45fSAndroid Build Coastguard Worker #define LOG_TAG "SurfaceComposerClient"
18*38e8c45fSAndroid Build Coastguard Worker
19*38e8c45fSAndroid Build Coastguard Worker #include <semaphore.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <stdint.h>
21*38e8c45fSAndroid Build Coastguard Worker #include <sys/types.h>
22*38e8c45fSAndroid Build Coastguard Worker
23*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/BnWindowInfosReportedListener.h>
24*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/DisplayState.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/EdgeExtensionParameters.h>
26*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/ISurfaceComposerClient.h>
27*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/IWindowInfosListener.h>
28*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/TrustedPresentationThresholds.h>
29*38e8c45fSAndroid Build Coastguard Worker #include <android/os/IInputConstants.h>
30*38e8c45fSAndroid Build Coastguard Worker #include <com_android_graphics_libgui_flags.h>
31*38e8c45fSAndroid Build Coastguard Worker #include <gui/DisplayLuts.h>
32*38e8c45fSAndroid Build Coastguard Worker #include <gui/FrameRateUtils.h>
33*38e8c45fSAndroid Build Coastguard Worker #include <gui/TraceUtils.h>
34*38e8c45fSAndroid Build Coastguard Worker #include <utils/Errors.h>
35*38e8c45fSAndroid Build Coastguard Worker #include <utils/Log.h>
36*38e8c45fSAndroid Build Coastguard Worker #include <utils/SortedVector.h>
37*38e8c45fSAndroid Build Coastguard Worker #include <utils/String8.h>
38*38e8c45fSAndroid Build Coastguard Worker #include <utils/threads.h>
39*38e8c45fSAndroid Build Coastguard Worker
40*38e8c45fSAndroid Build Coastguard Worker #include <binder/IPCThreadState.h>
41*38e8c45fSAndroid Build Coastguard Worker #include <binder/IServiceManager.h>
42*38e8c45fSAndroid Build Coastguard Worker #include <binder/ProcessState.h>
43*38e8c45fSAndroid Build Coastguard Worker
44*38e8c45fSAndroid Build Coastguard Worker #include <system/graphics.h>
45*38e8c45fSAndroid Build Coastguard Worker
46*38e8c45fSAndroid Build Coastguard Worker #include <gui/AidlUtil.h>
47*38e8c45fSAndroid Build Coastguard Worker #include <gui/BufferItemConsumer.h>
48*38e8c45fSAndroid Build Coastguard Worker #include <gui/CpuConsumer.h>
49*38e8c45fSAndroid Build Coastguard Worker #include <gui/IGraphicBufferProducer.h>
50*38e8c45fSAndroid Build Coastguard Worker #include <gui/ISurfaceComposer.h>
51*38e8c45fSAndroid Build Coastguard Worker #include <gui/LayerState.h>
52*38e8c45fSAndroid Build Coastguard Worker #include <gui/Surface.h>
53*38e8c45fSAndroid Build Coastguard Worker #include <gui/SurfaceComposerClient.h>
54*38e8c45fSAndroid Build Coastguard Worker #include <gui/WindowInfo.h>
55*38e8c45fSAndroid Build Coastguard Worker #include <private/gui/ParcelUtils.h>
56*38e8c45fSAndroid Build Coastguard Worker #include <ui/DisplayMode.h>
57*38e8c45fSAndroid Build Coastguard Worker #include <ui/DisplayState.h>
58*38e8c45fSAndroid Build Coastguard Worker #include <ui/DynamicDisplayInfo.h>
59*38e8c45fSAndroid Build Coastguard Worker #include <ui/FrameRateCategoryRate.h>
60*38e8c45fSAndroid Build Coastguard Worker
61*38e8c45fSAndroid Build Coastguard Worker #include <android-base/thread_annotations.h>
62*38e8c45fSAndroid Build Coastguard Worker #include <gui/LayerStatePermissions.h>
63*38e8c45fSAndroid Build Coastguard Worker #include <gui/ScreenCaptureResults.h>
64*38e8c45fSAndroid Build Coastguard Worker #include <private/gui/ComposerService.h>
65*38e8c45fSAndroid Build Coastguard Worker #include <private/gui/ComposerServiceAIDL.h>
66*38e8c45fSAndroid Build Coastguard Worker
67*38e8c45fSAndroid Build Coastguard Worker // This server size should always be smaller than the server cache size
68*38e8c45fSAndroid Build Coastguard Worker #define BUFFER_CACHE_MAX_SIZE 4096
69*38e8c45fSAndroid Build Coastguard Worker
70*38e8c45fSAndroid Build Coastguard Worker namespace android {
71*38e8c45fSAndroid Build Coastguard Worker
72*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::common::DisplayDecorationSupport;
73*38e8c45fSAndroid Build Coastguard Worker using gui::FocusRequest;
74*38e8c45fSAndroid Build Coastguard Worker using gui::IRegionSamplingListener;
75*38e8c45fSAndroid Build Coastguard Worker using gui::TrustedPresentationThresholds;
76*38e8c45fSAndroid Build Coastguard Worker using gui::WindowInfo;
77*38e8c45fSAndroid Build Coastguard Worker using gui::WindowInfoHandle;
78*38e8c45fSAndroid Build Coastguard Worker using gui::WindowInfosListener;
79*38e8c45fSAndroid Build Coastguard Worker using gui::aidl_utils::statusTFromBinderStatus;
80*38e8c45fSAndroid Build Coastguard Worker using ui::ColorMode;
81*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------
82*38e8c45fSAndroid Build Coastguard Worker
83*38e8c45fSAndroid Build Coastguard Worker ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService);
84*38e8c45fSAndroid Build Coastguard Worker ANDROID_SINGLETON_STATIC_INSTANCE(ComposerServiceAIDL);
85*38e8c45fSAndroid Build Coastguard Worker
86*38e8c45fSAndroid Build Coastguard Worker namespace {
87*38e8c45fSAndroid Build Coastguard Worker // Initialize transaction id counter used to generate transaction ids
88*38e8c45fSAndroid Build Coastguard Worker std::atomic<uint32_t> idCounter = 0;
generateId()89*38e8c45fSAndroid Build Coastguard Worker int64_t generateId() {
90*38e8c45fSAndroid Build Coastguard Worker return (((int64_t)getpid()) << 32) | ++idCounter;
91*38e8c45fSAndroid Build Coastguard Worker }
92*38e8c45fSAndroid Build Coastguard Worker
93*38e8c45fSAndroid Build Coastguard Worker constexpr int64_t INVALID_VSYNC = -1;
94*38e8c45fSAndroid Build Coastguard Worker const constexpr char* LOG_SURFACE_CONTROL_REGISTRY = "SurfaceControlRegistry";
95*38e8c45fSAndroid Build Coastguard Worker
96*38e8c45fSAndroid Build Coastguard Worker } // namespace
97*38e8c45fSAndroid Build Coastguard Worker
98*38e8c45fSAndroid Build Coastguard Worker const std::string SurfaceComposerClient::kEmpty{};
99*38e8c45fSAndroid Build Coastguard Worker
ComposerService()100*38e8c45fSAndroid Build Coastguard Worker ComposerService::ComposerService()
101*38e8c45fSAndroid Build Coastguard Worker : Singleton<ComposerService>() {
102*38e8c45fSAndroid Build Coastguard Worker Mutex::Autolock _l(mLock);
103*38e8c45fSAndroid Build Coastguard Worker connectLocked();
104*38e8c45fSAndroid Build Coastguard Worker }
105*38e8c45fSAndroid Build Coastguard Worker
connectLocked()106*38e8c45fSAndroid Build Coastguard Worker bool ComposerService::connectLocked() {
107*38e8c45fSAndroid Build Coastguard Worker const String16 name("SurfaceFlinger");
108*38e8c45fSAndroid Build Coastguard Worker mComposerService = waitForService<ISurfaceComposer>(name);
109*38e8c45fSAndroid Build Coastguard Worker if (mComposerService == nullptr) {
110*38e8c45fSAndroid Build Coastguard Worker return false; // fatal error or permission problem
111*38e8c45fSAndroid Build Coastguard Worker }
112*38e8c45fSAndroid Build Coastguard Worker
113*38e8c45fSAndroid Build Coastguard Worker // Create the death listener.
114*38e8c45fSAndroid Build Coastguard Worker class DeathObserver : public IBinder::DeathRecipient {
115*38e8c45fSAndroid Build Coastguard Worker ComposerService& mComposerService;
116*38e8c45fSAndroid Build Coastguard Worker virtual void binderDied(const wp<IBinder>& who) {
117*38e8c45fSAndroid Build Coastguard Worker ALOGW("ComposerService remote (surfaceflinger) died [%p]",
118*38e8c45fSAndroid Build Coastguard Worker who.unsafe_get());
119*38e8c45fSAndroid Build Coastguard Worker mComposerService.composerServiceDied();
120*38e8c45fSAndroid Build Coastguard Worker }
121*38e8c45fSAndroid Build Coastguard Worker public:
122*38e8c45fSAndroid Build Coastguard Worker explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { }
123*38e8c45fSAndroid Build Coastguard Worker };
124*38e8c45fSAndroid Build Coastguard Worker
125*38e8c45fSAndroid Build Coastguard Worker mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
126*38e8c45fSAndroid Build Coastguard Worker IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
127*38e8c45fSAndroid Build Coastguard Worker return true;
128*38e8c45fSAndroid Build Coastguard Worker }
129*38e8c45fSAndroid Build Coastguard Worker
getComposerService()130*38e8c45fSAndroid Build Coastguard Worker /*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
131*38e8c45fSAndroid Build Coastguard Worker ComposerService& instance = ComposerService::getInstance();
132*38e8c45fSAndroid Build Coastguard Worker Mutex::Autolock _l(instance.mLock);
133*38e8c45fSAndroid Build Coastguard Worker if (instance.mComposerService == nullptr) {
134*38e8c45fSAndroid Build Coastguard Worker if (ComposerService::getInstance().connectLocked()) {
135*38e8c45fSAndroid Build Coastguard Worker ALOGD("ComposerService reconnected");
136*38e8c45fSAndroid Build Coastguard Worker }
137*38e8c45fSAndroid Build Coastguard Worker }
138*38e8c45fSAndroid Build Coastguard Worker return instance.mComposerService;
139*38e8c45fSAndroid Build Coastguard Worker }
140*38e8c45fSAndroid Build Coastguard Worker
composerServiceDied()141*38e8c45fSAndroid Build Coastguard Worker void ComposerService::composerServiceDied()
142*38e8c45fSAndroid Build Coastguard Worker {
143*38e8c45fSAndroid Build Coastguard Worker Mutex::Autolock _l(mLock);
144*38e8c45fSAndroid Build Coastguard Worker mComposerService = nullptr;
145*38e8c45fSAndroid Build Coastguard Worker mDeathObserver = nullptr;
146*38e8c45fSAndroid Build Coastguard Worker }
147*38e8c45fSAndroid Build Coastguard Worker
ComposerServiceAIDL()148*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::ComposerServiceAIDL() : Singleton<ComposerServiceAIDL>() {
149*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock lock(mMutex);
150*38e8c45fSAndroid Build Coastguard Worker connectLocked();
151*38e8c45fSAndroid Build Coastguard Worker }
152*38e8c45fSAndroid Build Coastguard Worker
connectLocked()153*38e8c45fSAndroid Build Coastguard Worker bool ComposerServiceAIDL::connectLocked() {
154*38e8c45fSAndroid Build Coastguard Worker const String16 name("SurfaceFlingerAIDL");
155*38e8c45fSAndroid Build Coastguard Worker mComposerService = waitForService<gui::ISurfaceComposer>(name);
156*38e8c45fSAndroid Build Coastguard Worker if (mComposerService == nullptr) {
157*38e8c45fSAndroid Build Coastguard Worker return false; // fatal error or permission problem
158*38e8c45fSAndroid Build Coastguard Worker }
159*38e8c45fSAndroid Build Coastguard Worker
160*38e8c45fSAndroid Build Coastguard Worker // Create the death listener.
161*38e8c45fSAndroid Build Coastguard Worker class DeathObserver : public IBinder::DeathRecipient {
162*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL& mComposerService;
163*38e8c45fSAndroid Build Coastguard Worker virtual void binderDied(const wp<IBinder>& who) {
164*38e8c45fSAndroid Build Coastguard Worker ALOGW("ComposerService aidl remote (surfaceflinger) died [%p]", who.unsafe_get());
165*38e8c45fSAndroid Build Coastguard Worker mComposerService.composerServiceDied();
166*38e8c45fSAndroid Build Coastguard Worker }
167*38e8c45fSAndroid Build Coastguard Worker
168*38e8c45fSAndroid Build Coastguard Worker public:
169*38e8c45fSAndroid Build Coastguard Worker explicit DeathObserver(ComposerServiceAIDL& mgr) : mComposerService(mgr) {}
170*38e8c45fSAndroid Build Coastguard Worker };
171*38e8c45fSAndroid Build Coastguard Worker
172*38e8c45fSAndroid Build Coastguard Worker mDeathObserver = new DeathObserver(*const_cast<ComposerServiceAIDL*>(this));
173*38e8c45fSAndroid Build Coastguard Worker IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
174*38e8c45fSAndroid Build Coastguard Worker return true;
175*38e8c45fSAndroid Build Coastguard Worker }
176*38e8c45fSAndroid Build Coastguard Worker
getComposerService()177*38e8c45fSAndroid Build Coastguard Worker /*static*/ sp<gui::ISurfaceComposer> ComposerServiceAIDL::getComposerService() {
178*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL& instance = ComposerServiceAIDL::getInstance();
179*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock lock(instance.mMutex);
180*38e8c45fSAndroid Build Coastguard Worker if (instance.mComposerService == nullptr) {
181*38e8c45fSAndroid Build Coastguard Worker if (ComposerServiceAIDL::getInstance().connectLocked()) {
182*38e8c45fSAndroid Build Coastguard Worker ALOGD("ComposerServiceAIDL reconnected");
183*38e8c45fSAndroid Build Coastguard Worker WindowInfosListenerReporter::getInstance()->reconnect(instance.mComposerService);
184*38e8c45fSAndroid Build Coastguard Worker }
185*38e8c45fSAndroid Build Coastguard Worker }
186*38e8c45fSAndroid Build Coastguard Worker return instance.mComposerService;
187*38e8c45fSAndroid Build Coastguard Worker }
188*38e8c45fSAndroid Build Coastguard Worker
composerServiceDied()189*38e8c45fSAndroid Build Coastguard Worker void ComposerServiceAIDL::composerServiceDied() {
190*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock lock(mMutex);
191*38e8c45fSAndroid Build Coastguard Worker mComposerService = nullptr;
192*38e8c45fSAndroid Build Coastguard Worker mDeathObserver = nullptr;
193*38e8c45fSAndroid Build Coastguard Worker }
194*38e8c45fSAndroid Build Coastguard Worker
195*38e8c45fSAndroid Build Coastguard Worker class DefaultComposerClient: public Singleton<DefaultComposerClient> {
196*38e8c45fSAndroid Build Coastguard Worker Mutex mLock;
197*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceComposerClient> mClient;
198*38e8c45fSAndroid Build Coastguard Worker friend class Singleton<ComposerService>;
199*38e8c45fSAndroid Build Coastguard Worker public:
getComposerClient()200*38e8c45fSAndroid Build Coastguard Worker static sp<SurfaceComposerClient> getComposerClient() {
201*38e8c45fSAndroid Build Coastguard Worker DefaultComposerClient& dc = DefaultComposerClient::getInstance();
202*38e8c45fSAndroid Build Coastguard Worker Mutex::Autolock _l(dc.mLock);
203*38e8c45fSAndroid Build Coastguard Worker if (dc.mClient == nullptr) {
204*38e8c45fSAndroid Build Coastguard Worker dc.mClient = new SurfaceComposerClient;
205*38e8c45fSAndroid Build Coastguard Worker }
206*38e8c45fSAndroid Build Coastguard Worker return dc.mClient;
207*38e8c45fSAndroid Build Coastguard Worker }
208*38e8c45fSAndroid Build Coastguard Worker };
209*38e8c45fSAndroid Build Coastguard Worker ANDROID_SINGLETON_STATIC_INSTANCE(DefaultComposerClient);
210*38e8c45fSAndroid Build Coastguard Worker
211*38e8c45fSAndroid Build Coastguard Worker
getDefault()212*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceComposerClient> SurfaceComposerClient::getDefault() {
213*38e8c45fSAndroid Build Coastguard Worker return DefaultComposerClient::getComposerClient();
214*38e8c45fSAndroid Build Coastguard Worker }
215*38e8c45fSAndroid Build Coastguard Worker
216*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------
217*38e8c45fSAndroid Build Coastguard Worker
~JankDataListener()218*38e8c45fSAndroid Build Coastguard Worker JankDataListener::~JankDataListener() {
219*38e8c45fSAndroid Build Coastguard Worker }
220*38e8c45fSAndroid Build Coastguard Worker
flushJankData()221*38e8c45fSAndroid Build Coastguard Worker status_t JankDataListener::flushJankData() {
222*38e8c45fSAndroid Build Coastguard Worker if (mLayerId == -1) {
223*38e8c45fSAndroid Build Coastguard Worker return INVALID_OPERATION;
224*38e8c45fSAndroid Build Coastguard Worker }
225*38e8c45fSAndroid Build Coastguard Worker
226*38e8c45fSAndroid Build Coastguard Worker binder::Status status = ComposerServiceAIDL::getComposerService()->flushJankData(mLayerId);
227*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
228*38e8c45fSAndroid Build Coastguard Worker }
229*38e8c45fSAndroid Build Coastguard Worker
230*38e8c45fSAndroid Build Coastguard Worker std::mutex JankDataListenerFanOut::sFanoutInstanceMutex;
231*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<int32_t, sp<JankDataListenerFanOut>> JankDataListenerFanOut::sFanoutInstances;
232*38e8c45fSAndroid Build Coastguard Worker
onJankData(const std::vector<gui::JankData> & jankData)233*38e8c45fSAndroid Build Coastguard Worker binder::Status JankDataListenerFanOut::onJankData(const std::vector<gui::JankData>& jankData) {
234*38e8c45fSAndroid Build Coastguard Worker // Find the highest VSync ID.
235*38e8c45fSAndroid Build Coastguard Worker int64_t lastVsync = jankData.empty()
236*38e8c45fSAndroid Build Coastguard Worker ? 0
237*38e8c45fSAndroid Build Coastguard Worker : std::max_element(jankData.begin(), jankData.end(),
238*38e8c45fSAndroid Build Coastguard Worker [](const gui::JankData& jd1, const gui::JankData& jd2) {
239*38e8c45fSAndroid Build Coastguard Worker return jd1.frameVsyncId < jd2.frameVsyncId;
240*38e8c45fSAndroid Build Coastguard Worker })
241*38e8c45fSAndroid Build Coastguard Worker ->frameVsyncId;
242*38e8c45fSAndroid Build Coastguard Worker
243*38e8c45fSAndroid Build Coastguard Worker // Fan out the jank data callback.
244*38e8c45fSAndroid Build Coastguard Worker std::vector<wp<JankDataListener>> listenersToRemove;
245*38e8c45fSAndroid Build Coastguard Worker for (auto listener : getActiveListeners()) {
246*38e8c45fSAndroid Build Coastguard Worker if (!listener->onJankDataAvailable(jankData) ||
247*38e8c45fSAndroid Build Coastguard Worker (listener->mRemoveAfter >= 0 && listener->mRemoveAfter <= lastVsync)) {
248*38e8c45fSAndroid Build Coastguard Worker listenersToRemove.push_back(listener);
249*38e8c45fSAndroid Build Coastguard Worker }
250*38e8c45fSAndroid Build Coastguard Worker }
251*38e8c45fSAndroid Build Coastguard Worker
252*38e8c45fSAndroid Build Coastguard Worker return removeListeners(listenersToRemove)
253*38e8c45fSAndroid Build Coastguard Worker ? binder::Status::ok()
254*38e8c45fSAndroid Build Coastguard Worker : binder::Status::fromExceptionCode(binder::Status::EX_NULL_POINTER);
255*38e8c45fSAndroid Build Coastguard Worker }
256*38e8c45fSAndroid Build Coastguard Worker
addListener(sp<SurfaceControl> sc,sp<JankDataListener> listener)257*38e8c45fSAndroid Build Coastguard Worker status_t JankDataListenerFanOut::addListener(sp<SurfaceControl> sc, sp<JankDataListener> listener) {
258*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> layer = sc->getHandle();
259*38e8c45fSAndroid Build Coastguard Worker if (layer == nullptr) {
260*38e8c45fSAndroid Build Coastguard Worker return UNEXPECTED_NULL;
261*38e8c45fSAndroid Build Coastguard Worker }
262*38e8c45fSAndroid Build Coastguard Worker int32_t layerId = sc->getLayerId();
263*38e8c45fSAndroid Build Coastguard Worker
264*38e8c45fSAndroid Build Coastguard Worker sFanoutInstanceMutex.lock();
265*38e8c45fSAndroid Build Coastguard Worker auto it = sFanoutInstances.find(layerId);
266*38e8c45fSAndroid Build Coastguard Worker bool registerNeeded = it == sFanoutInstances.end();
267*38e8c45fSAndroid Build Coastguard Worker sp<JankDataListenerFanOut> fanout;
268*38e8c45fSAndroid Build Coastguard Worker if (registerNeeded) {
269*38e8c45fSAndroid Build Coastguard Worker fanout = sp<JankDataListenerFanOut>::make(layerId);
270*38e8c45fSAndroid Build Coastguard Worker sFanoutInstances.insert({layerId, fanout});
271*38e8c45fSAndroid Build Coastguard Worker } else {
272*38e8c45fSAndroid Build Coastguard Worker fanout = it->second;
273*38e8c45fSAndroid Build Coastguard Worker }
274*38e8c45fSAndroid Build Coastguard Worker
275*38e8c45fSAndroid Build Coastguard Worker fanout->mMutex.lock();
276*38e8c45fSAndroid Build Coastguard Worker fanout->mListeners.insert(listener);
277*38e8c45fSAndroid Build Coastguard Worker fanout->mMutex.unlock();
278*38e8c45fSAndroid Build Coastguard Worker
279*38e8c45fSAndroid Build Coastguard Worker sFanoutInstanceMutex.unlock();
280*38e8c45fSAndroid Build Coastguard Worker
281*38e8c45fSAndroid Build Coastguard Worker if (registerNeeded) {
282*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
283*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->addJankListener(layer, fanout);
284*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
285*38e8c45fSAndroid Build Coastguard Worker }
286*38e8c45fSAndroid Build Coastguard Worker return OK;
287*38e8c45fSAndroid Build Coastguard Worker }
288*38e8c45fSAndroid Build Coastguard Worker
removeListener(sp<JankDataListener> listener)289*38e8c45fSAndroid Build Coastguard Worker status_t JankDataListenerFanOut::removeListener(sp<JankDataListener> listener) {
290*38e8c45fSAndroid Build Coastguard Worker int32_t layerId = listener->mLayerId;
291*38e8c45fSAndroid Build Coastguard Worker if (layerId == -1) {
292*38e8c45fSAndroid Build Coastguard Worker return INVALID_OPERATION;
293*38e8c45fSAndroid Build Coastguard Worker }
294*38e8c45fSAndroid Build Coastguard Worker
295*38e8c45fSAndroid Build Coastguard Worker int64_t removeAfter = INVALID_VSYNC;
296*38e8c45fSAndroid Build Coastguard Worker sp<JankDataListenerFanOut> fanout;
297*38e8c45fSAndroid Build Coastguard Worker
298*38e8c45fSAndroid Build Coastguard Worker sFanoutInstanceMutex.lock();
299*38e8c45fSAndroid Build Coastguard Worker auto it = sFanoutInstances.find(layerId);
300*38e8c45fSAndroid Build Coastguard Worker if (it != sFanoutInstances.end()) {
301*38e8c45fSAndroid Build Coastguard Worker fanout = it->second;
302*38e8c45fSAndroid Build Coastguard Worker removeAfter = fanout->updateAndGetRemovalVSync();
303*38e8c45fSAndroid Build Coastguard Worker }
304*38e8c45fSAndroid Build Coastguard Worker
305*38e8c45fSAndroid Build Coastguard Worker if (removeAfter != INVALID_VSYNC) {
306*38e8c45fSAndroid Build Coastguard Worker // Remove this instance from the map, so that no new listeners are added
307*38e8c45fSAndroid Build Coastguard Worker // while we're scheduled to be removed.
308*38e8c45fSAndroid Build Coastguard Worker sFanoutInstances.erase(layerId);
309*38e8c45fSAndroid Build Coastguard Worker }
310*38e8c45fSAndroid Build Coastguard Worker sFanoutInstanceMutex.unlock();
311*38e8c45fSAndroid Build Coastguard Worker
312*38e8c45fSAndroid Build Coastguard Worker if (removeAfter < 0) {
313*38e8c45fSAndroid Build Coastguard Worker return OK;
314*38e8c45fSAndroid Build Coastguard Worker }
315*38e8c45fSAndroid Build Coastguard Worker
316*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
317*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->removeJankListener(layerId, fanout,
318*38e8c45fSAndroid Build Coastguard Worker removeAfter);
319*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
320*38e8c45fSAndroid Build Coastguard Worker }
321*38e8c45fSAndroid Build Coastguard Worker
getActiveListeners()322*38e8c45fSAndroid Build Coastguard Worker std::vector<sp<JankDataListener>> JankDataListenerFanOut::getActiveListeners() {
323*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
324*38e8c45fSAndroid Build Coastguard Worker
325*38e8c45fSAndroid Build Coastguard Worker std::vector<sp<JankDataListener>> listeners;
326*38e8c45fSAndroid Build Coastguard Worker for (auto it = mListeners.begin(); it != mListeners.end();) {
327*38e8c45fSAndroid Build Coastguard Worker auto listener = it->promote();
328*38e8c45fSAndroid Build Coastguard Worker if (!listener) {
329*38e8c45fSAndroid Build Coastguard Worker it = mListeners.erase(it);
330*38e8c45fSAndroid Build Coastguard Worker } else {
331*38e8c45fSAndroid Build Coastguard Worker listeners.push_back(std::move(listener));
332*38e8c45fSAndroid Build Coastguard Worker it++;
333*38e8c45fSAndroid Build Coastguard Worker }
334*38e8c45fSAndroid Build Coastguard Worker }
335*38e8c45fSAndroid Build Coastguard Worker return listeners;
336*38e8c45fSAndroid Build Coastguard Worker }
337*38e8c45fSAndroid Build Coastguard Worker
removeListeners(const std::vector<wp<JankDataListener>> & listeners)338*38e8c45fSAndroid Build Coastguard Worker bool JankDataListenerFanOut::removeListeners(const std::vector<wp<JankDataListener>>& listeners) {
339*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> fanoutLock(sFanoutInstanceMutex);
340*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> listenersLock(mMutex);
341*38e8c45fSAndroid Build Coastguard Worker
342*38e8c45fSAndroid Build Coastguard Worker for (auto listener : listeners) {
343*38e8c45fSAndroid Build Coastguard Worker mListeners.erase(listener);
344*38e8c45fSAndroid Build Coastguard Worker }
345*38e8c45fSAndroid Build Coastguard Worker
346*38e8c45fSAndroid Build Coastguard Worker if (mListeners.empty()) {
347*38e8c45fSAndroid Build Coastguard Worker sFanoutInstances.erase(mLayerId);
348*38e8c45fSAndroid Build Coastguard Worker return false;
349*38e8c45fSAndroid Build Coastguard Worker }
350*38e8c45fSAndroid Build Coastguard Worker return true;
351*38e8c45fSAndroid Build Coastguard Worker }
352*38e8c45fSAndroid Build Coastguard Worker
updateAndGetRemovalVSync()353*38e8c45fSAndroid Build Coastguard Worker int64_t JankDataListenerFanOut::updateAndGetRemovalVSync() {
354*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
355*38e8c45fSAndroid Build Coastguard Worker if (mRemoveAfter >= 0) {
356*38e8c45fSAndroid Build Coastguard Worker // We've already been scheduled to be removed. Don't schedule again.
357*38e8c45fSAndroid Build Coastguard Worker return INVALID_VSYNC;
358*38e8c45fSAndroid Build Coastguard Worker }
359*38e8c45fSAndroid Build Coastguard Worker
360*38e8c45fSAndroid Build Coastguard Worker int64_t removeAfter = 0;
361*38e8c45fSAndroid Build Coastguard Worker for (auto it = mListeners.begin(); it != mListeners.end();) {
362*38e8c45fSAndroid Build Coastguard Worker auto listener = it->promote();
363*38e8c45fSAndroid Build Coastguard Worker if (!listener) {
364*38e8c45fSAndroid Build Coastguard Worker it = mListeners.erase(it);
365*38e8c45fSAndroid Build Coastguard Worker } else if (listener->mRemoveAfter < 0) {
366*38e8c45fSAndroid Build Coastguard Worker // We have at least one listener that's still interested. Don't remove.
367*38e8c45fSAndroid Build Coastguard Worker return INVALID_VSYNC;
368*38e8c45fSAndroid Build Coastguard Worker } else {
369*38e8c45fSAndroid Build Coastguard Worker removeAfter = std::max(removeAfter, listener->mRemoveAfter);
370*38e8c45fSAndroid Build Coastguard Worker it++;
371*38e8c45fSAndroid Build Coastguard Worker }
372*38e8c45fSAndroid Build Coastguard Worker }
373*38e8c45fSAndroid Build Coastguard Worker
374*38e8c45fSAndroid Build Coastguard Worker mRemoveAfter = removeAfter;
375*38e8c45fSAndroid Build Coastguard Worker return removeAfter;
376*38e8c45fSAndroid Build Coastguard Worker }
377*38e8c45fSAndroid Build Coastguard Worker
378*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------
379*38e8c45fSAndroid Build Coastguard Worker
380*38e8c45fSAndroid Build Coastguard Worker // TransactionCompletedListener does not use ANDROID_SINGLETON_STATIC_INSTANCE because it needs
381*38e8c45fSAndroid Build Coastguard Worker // to be able to return a sp<> to its instance to pass to SurfaceFlinger.
382*38e8c45fSAndroid Build Coastguard Worker // ANDROID_SINGLETON_STATIC_INSTANCE only allows a reference to an instance.
383*38e8c45fSAndroid Build Coastguard Worker
384*38e8c45fSAndroid Build Coastguard Worker // 0 is an invalid callback id
TransactionCompletedListener()385*38e8c45fSAndroid Build Coastguard Worker TransactionCompletedListener::TransactionCompletedListener() : mCallbackIdCounter(1) {}
386*38e8c45fSAndroid Build Coastguard Worker
getNextIdLocked()387*38e8c45fSAndroid Build Coastguard Worker int64_t TransactionCompletedListener::getNextIdLocked() {
388*38e8c45fSAndroid Build Coastguard Worker return mCallbackIdCounter++;
389*38e8c45fSAndroid Build Coastguard Worker }
390*38e8c45fSAndroid Build Coastguard Worker
391*38e8c45fSAndroid Build Coastguard Worker sp<TransactionCompletedListener> TransactionCompletedListener::sInstance = nullptr;
392*38e8c45fSAndroid Build Coastguard Worker static std::mutex sListenerInstanceMutex;
393*38e8c45fSAndroid Build Coastguard Worker
setInstance(const sp<TransactionCompletedListener> & listener)394*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::setInstance(const sp<TransactionCompletedListener>& listener) {
395*38e8c45fSAndroid Build Coastguard Worker sInstance = listener;
396*38e8c45fSAndroid Build Coastguard Worker }
397*38e8c45fSAndroid Build Coastguard Worker
getInstance()398*38e8c45fSAndroid Build Coastguard Worker sp<TransactionCompletedListener> TransactionCompletedListener::getInstance() {
399*38e8c45fSAndroid Build Coastguard Worker std::lock_guard<std::mutex> lock(sListenerInstanceMutex);
400*38e8c45fSAndroid Build Coastguard Worker if (sInstance == nullptr) {
401*38e8c45fSAndroid Build Coastguard Worker sInstance = new TransactionCompletedListener;
402*38e8c45fSAndroid Build Coastguard Worker }
403*38e8c45fSAndroid Build Coastguard Worker return sInstance;
404*38e8c45fSAndroid Build Coastguard Worker }
405*38e8c45fSAndroid Build Coastguard Worker
getIInstance()406*38e8c45fSAndroid Build Coastguard Worker sp<ITransactionCompletedListener> TransactionCompletedListener::getIInstance() {
407*38e8c45fSAndroid Build Coastguard Worker return static_cast<sp<ITransactionCompletedListener>>(getInstance());
408*38e8c45fSAndroid Build Coastguard Worker }
409*38e8c45fSAndroid Build Coastguard Worker
startListeningLocked()410*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::startListeningLocked() {
411*38e8c45fSAndroid Build Coastguard Worker if (mListening) {
412*38e8c45fSAndroid Build Coastguard Worker return;
413*38e8c45fSAndroid Build Coastguard Worker }
414*38e8c45fSAndroid Build Coastguard Worker ProcessState::self()->startThreadPool();
415*38e8c45fSAndroid Build Coastguard Worker mListening = true;
416*38e8c45fSAndroid Build Coastguard Worker }
417*38e8c45fSAndroid Build Coastguard Worker
addCallbackFunction(const TransactionCompletedCallback & callbackFunction,const std::unordered_set<sp<SurfaceControl>,SurfaceComposerClient::SCHash> & surfaceControls,CallbackId::Type callbackType)418*38e8c45fSAndroid Build Coastguard Worker CallbackId TransactionCompletedListener::addCallbackFunction(
419*38e8c45fSAndroid Build Coastguard Worker const TransactionCompletedCallback& callbackFunction,
420*38e8c45fSAndroid Build Coastguard Worker const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
421*38e8c45fSAndroid Build Coastguard Worker surfaceControls,
422*38e8c45fSAndroid Build Coastguard Worker CallbackId::Type callbackType) {
423*38e8c45fSAndroid Build Coastguard Worker std::lock_guard<std::mutex> lock(mMutex);
424*38e8c45fSAndroid Build Coastguard Worker startListeningLocked();
425*38e8c45fSAndroid Build Coastguard Worker
426*38e8c45fSAndroid Build Coastguard Worker CallbackId callbackId(getNextIdLocked(), callbackType);
427*38e8c45fSAndroid Build Coastguard Worker mCallbacks[callbackId].callbackFunction = callbackFunction;
428*38e8c45fSAndroid Build Coastguard Worker auto& callbackSurfaceControls = mCallbacks[callbackId].surfaceControls;
429*38e8c45fSAndroid Build Coastguard Worker
430*38e8c45fSAndroid Build Coastguard Worker for (const auto& surfaceControl : surfaceControls) {
431*38e8c45fSAndroid Build Coastguard Worker callbackSurfaceControls[surfaceControl->getHandle()] = surfaceControl;
432*38e8c45fSAndroid Build Coastguard Worker }
433*38e8c45fSAndroid Build Coastguard Worker
434*38e8c45fSAndroid Build Coastguard Worker return callbackId;
435*38e8c45fSAndroid Build Coastguard Worker }
436*38e8c45fSAndroid Build Coastguard Worker
setReleaseBufferCallback(const ReleaseCallbackId & callbackId,ReleaseBufferCallback listener)437*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::setReleaseBufferCallback(const ReleaseCallbackId& callbackId,
438*38e8c45fSAndroid Build Coastguard Worker ReleaseBufferCallback listener) {
439*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
440*38e8c45fSAndroid Build Coastguard Worker mReleaseBufferCallbacks[callbackId] = listener;
441*38e8c45fSAndroid Build Coastguard Worker }
442*38e8c45fSAndroid Build Coastguard Worker
addSurfaceStatsListener(void * context,void * cookie,sp<SurfaceControl> surfaceControl,SurfaceStatsCallback listener)443*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::addSurfaceStatsListener(void* context, void* cookie,
444*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl, SurfaceStatsCallback listener) {
445*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::recursive_mutex> lock(mSurfaceStatsListenerMutex);
446*38e8c45fSAndroid Build Coastguard Worker mSurfaceStatsListeners.insert(
447*38e8c45fSAndroid Build Coastguard Worker {surfaceControl->getLayerId(), SurfaceStatsCallbackEntry(context, cookie, listener)});
448*38e8c45fSAndroid Build Coastguard Worker }
449*38e8c45fSAndroid Build Coastguard Worker
removeSurfaceStatsListener(void * context,void * cookie)450*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::removeSurfaceStatsListener(void* context, void* cookie) {
451*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::recursive_mutex> lock(mSurfaceStatsListenerMutex);
452*38e8c45fSAndroid Build Coastguard Worker for (auto it = mSurfaceStatsListeners.begin(); it != mSurfaceStatsListeners.end();) {
453*38e8c45fSAndroid Build Coastguard Worker auto [itContext, itCookie, itListener] = it->second;
454*38e8c45fSAndroid Build Coastguard Worker if (itContext == context && itCookie == cookie) {
455*38e8c45fSAndroid Build Coastguard Worker it = mSurfaceStatsListeners.erase(it);
456*38e8c45fSAndroid Build Coastguard Worker } else {
457*38e8c45fSAndroid Build Coastguard Worker it++;
458*38e8c45fSAndroid Build Coastguard Worker }
459*38e8c45fSAndroid Build Coastguard Worker }
460*38e8c45fSAndroid Build Coastguard Worker }
461*38e8c45fSAndroid Build Coastguard Worker
addSurfaceControlToCallbacks(const sp<SurfaceControl> & surfaceControl,const std::unordered_set<CallbackId,CallbackIdHash> & callbackIds)462*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::addSurfaceControlToCallbacks(
463*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& surfaceControl,
464*38e8c45fSAndroid Build Coastguard Worker const std::unordered_set<CallbackId, CallbackIdHash>& callbackIds) {
465*38e8c45fSAndroid Build Coastguard Worker std::lock_guard<std::mutex> lock(mMutex);
466*38e8c45fSAndroid Build Coastguard Worker
467*38e8c45fSAndroid Build Coastguard Worker for (auto callbackId : callbackIds) {
468*38e8c45fSAndroid Build Coastguard Worker mCallbacks[callbackId].surfaceControls.emplace(std::piecewise_construct,
469*38e8c45fSAndroid Build Coastguard Worker std::forward_as_tuple(
470*38e8c45fSAndroid Build Coastguard Worker surfaceControl->getHandle()),
471*38e8c45fSAndroid Build Coastguard Worker std::forward_as_tuple(surfaceControl));
472*38e8c45fSAndroid Build Coastguard Worker }
473*38e8c45fSAndroid Build Coastguard Worker }
474*38e8c45fSAndroid Build Coastguard Worker
onTransactionCompleted(ListenerStats listenerStats)475*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::onTransactionCompleted(ListenerStats listenerStats) {
476*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<CallbackId, CallbackTranslation, CallbackIdHash> callbacksMap;
477*38e8c45fSAndroid Build Coastguard Worker {
478*38e8c45fSAndroid Build Coastguard Worker std::lock_guard<std::mutex> lock(mMutex);
479*38e8c45fSAndroid Build Coastguard Worker
480*38e8c45fSAndroid Build Coastguard Worker /* This listener knows all the sp<IBinder> to sp<SurfaceControl> for all its registered
481*38e8c45fSAndroid Build Coastguard Worker * callbackIds, except for when Transactions are merged together. This probably cannot be
482*38e8c45fSAndroid Build Coastguard Worker * solved before this point because the Transactions could be merged together and applied in
483*38e8c45fSAndroid Build Coastguard Worker * a different process.
484*38e8c45fSAndroid Build Coastguard Worker *
485*38e8c45fSAndroid Build Coastguard Worker * Fortunately, we get all the callbacks for this listener for the same frame together at
486*38e8c45fSAndroid Build Coastguard Worker * the same time. This means if any Transactions were merged together, we will get their
487*38e8c45fSAndroid Build Coastguard Worker * callbacks at the same time. We can combine all the sp<IBinder> to sp<SurfaceControl> maps
488*38e8c45fSAndroid Build Coastguard Worker * for all the callbackIds to generate one super map that contains all the sp<IBinder> to
489*38e8c45fSAndroid Build Coastguard Worker * sp<SurfaceControl> that could possibly exist for the callbacks.
490*38e8c45fSAndroid Build Coastguard Worker */
491*38e8c45fSAndroid Build Coastguard Worker callbacksMap = mCallbacks;
492*38e8c45fSAndroid Build Coastguard Worker for (const auto& transactionStats : listenerStats.transactionStats) {
493*38e8c45fSAndroid Build Coastguard Worker for (auto& callbackId : transactionStats.callbackIds) {
494*38e8c45fSAndroid Build Coastguard Worker mCallbacks.erase(callbackId);
495*38e8c45fSAndroid Build Coastguard Worker }
496*38e8c45fSAndroid Build Coastguard Worker }
497*38e8c45fSAndroid Build Coastguard Worker }
498*38e8c45fSAndroid Build Coastguard Worker for (const auto& transactionStats : listenerStats.transactionStats) {
499*38e8c45fSAndroid Build Coastguard Worker // handle on commit callbacks
500*38e8c45fSAndroid Build Coastguard Worker for (auto callbackId : transactionStats.callbackIds) {
501*38e8c45fSAndroid Build Coastguard Worker if (callbackId.type != CallbackId::Type::ON_COMMIT) {
502*38e8c45fSAndroid Build Coastguard Worker continue;
503*38e8c45fSAndroid Build Coastguard Worker }
504*38e8c45fSAndroid Build Coastguard Worker auto& [callbackFunction, callbackSurfaceControls] = callbacksMap[callbackId];
505*38e8c45fSAndroid Build Coastguard Worker if (!callbackFunction) {
506*38e8c45fSAndroid Build Coastguard Worker continue;
507*38e8c45fSAndroid Build Coastguard Worker }
508*38e8c45fSAndroid Build Coastguard Worker std::vector<SurfaceControlStats> surfaceControlStats;
509*38e8c45fSAndroid Build Coastguard Worker for (const auto& surfaceStats : transactionStats.surfaceStats) {
510*38e8c45fSAndroid Build Coastguard Worker surfaceControlStats
511*38e8c45fSAndroid Build Coastguard Worker .emplace_back(callbacksMap[callbackId]
512*38e8c45fSAndroid Build Coastguard Worker .surfaceControls[surfaceStats.surfaceControl],
513*38e8c45fSAndroid Build Coastguard Worker transactionStats.latchTime, surfaceStats.acquireTimeOrFence,
514*38e8c45fSAndroid Build Coastguard Worker transactionStats.presentFence,
515*38e8c45fSAndroid Build Coastguard Worker surfaceStats.previousReleaseFence, surfaceStats.transformHint,
516*38e8c45fSAndroid Build Coastguard Worker surfaceStats.eventStats,
517*38e8c45fSAndroid Build Coastguard Worker surfaceStats.currentMaxAcquiredBufferCount);
518*38e8c45fSAndroid Build Coastguard Worker }
519*38e8c45fSAndroid Build Coastguard Worker
520*38e8c45fSAndroid Build Coastguard Worker callbackFunction(transactionStats.latchTime, transactionStats.presentFence,
521*38e8c45fSAndroid Build Coastguard Worker surfaceControlStats);
522*38e8c45fSAndroid Build Coastguard Worker
523*38e8c45fSAndroid Build Coastguard Worker // More than one transaction may contain the same callback id. Erase the callback from
524*38e8c45fSAndroid Build Coastguard Worker // the map to ensure that it is only called once. This can happen if transactions are
525*38e8c45fSAndroid Build Coastguard Worker // parcelled out of process and applied in both processes.
526*38e8c45fSAndroid Build Coastguard Worker callbacksMap.erase(callbackId);
527*38e8c45fSAndroid Build Coastguard Worker }
528*38e8c45fSAndroid Build Coastguard Worker
529*38e8c45fSAndroid Build Coastguard Worker // handle on complete callbacks
530*38e8c45fSAndroid Build Coastguard Worker for (auto callbackId : transactionStats.callbackIds) {
531*38e8c45fSAndroid Build Coastguard Worker if (callbackId.type != CallbackId::Type::ON_COMPLETE) {
532*38e8c45fSAndroid Build Coastguard Worker continue;
533*38e8c45fSAndroid Build Coastguard Worker }
534*38e8c45fSAndroid Build Coastguard Worker auto& [callbackFunction, callbackSurfaceControls] = callbacksMap[callbackId];
535*38e8c45fSAndroid Build Coastguard Worker if (!callbackFunction) {
536*38e8c45fSAndroid Build Coastguard Worker ALOGE("cannot call null callback function, skipping");
537*38e8c45fSAndroid Build Coastguard Worker continue;
538*38e8c45fSAndroid Build Coastguard Worker }
539*38e8c45fSAndroid Build Coastguard Worker std::vector<SurfaceControlStats> surfaceControlStats;
540*38e8c45fSAndroid Build Coastguard Worker for (const auto& surfaceStats : transactionStats.surfaceStats) {
541*38e8c45fSAndroid Build Coastguard Worker surfaceControlStats
542*38e8c45fSAndroid Build Coastguard Worker .emplace_back(callbacksMap[callbackId]
543*38e8c45fSAndroid Build Coastguard Worker .surfaceControls[surfaceStats.surfaceControl],
544*38e8c45fSAndroid Build Coastguard Worker transactionStats.latchTime, surfaceStats.acquireTimeOrFence,
545*38e8c45fSAndroid Build Coastguard Worker transactionStats.presentFence,
546*38e8c45fSAndroid Build Coastguard Worker surfaceStats.previousReleaseFence, surfaceStats.transformHint,
547*38e8c45fSAndroid Build Coastguard Worker surfaceStats.eventStats,
548*38e8c45fSAndroid Build Coastguard Worker surfaceStats.currentMaxAcquiredBufferCount);
549*38e8c45fSAndroid Build Coastguard Worker if (callbacksMap[callbackId].surfaceControls[surfaceStats.surfaceControl] &&
550*38e8c45fSAndroid Build Coastguard Worker surfaceStats.transformHint.has_value()) {
551*38e8c45fSAndroid Build Coastguard Worker callbacksMap[callbackId]
552*38e8c45fSAndroid Build Coastguard Worker .surfaceControls[surfaceStats.surfaceControl]
553*38e8c45fSAndroid Build Coastguard Worker ->setTransformHint(*surfaceStats.transformHint);
554*38e8c45fSAndroid Build Coastguard Worker }
555*38e8c45fSAndroid Build Coastguard Worker // If there is buffer id set, we look up any pending client release buffer callbacks
556*38e8c45fSAndroid Build Coastguard Worker // and call them. This is a performance optimization when we have a transaction
557*38e8c45fSAndroid Build Coastguard Worker // callback and a release buffer callback happening at the same time to avoid an
558*38e8c45fSAndroid Build Coastguard Worker // additional ipc call from the server.
559*38e8c45fSAndroid Build Coastguard Worker if (surfaceStats.previousReleaseCallbackId != ReleaseCallbackId::INVALID_ID) {
560*38e8c45fSAndroid Build Coastguard Worker ReleaseBufferCallback callback;
561*38e8c45fSAndroid Build Coastguard Worker {
562*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
563*38e8c45fSAndroid Build Coastguard Worker callback = popReleaseBufferCallbackLocked(
564*38e8c45fSAndroid Build Coastguard Worker surfaceStats.previousReleaseCallbackId);
565*38e8c45fSAndroid Build Coastguard Worker }
566*38e8c45fSAndroid Build Coastguard Worker if (callback) {
567*38e8c45fSAndroid Build Coastguard Worker callback(surfaceStats.previousReleaseCallbackId,
568*38e8c45fSAndroid Build Coastguard Worker surfaceStats.previousReleaseFence
569*38e8c45fSAndroid Build Coastguard Worker ? surfaceStats.previousReleaseFence
570*38e8c45fSAndroid Build Coastguard Worker : Fence::NO_FENCE,
571*38e8c45fSAndroid Build Coastguard Worker surfaceStats.currentMaxAcquiredBufferCount);
572*38e8c45fSAndroid Build Coastguard Worker }
573*38e8c45fSAndroid Build Coastguard Worker }
574*38e8c45fSAndroid Build Coastguard Worker }
575*38e8c45fSAndroid Build Coastguard Worker
576*38e8c45fSAndroid Build Coastguard Worker callbackFunction(transactionStats.latchTime, transactionStats.presentFence,
577*38e8c45fSAndroid Build Coastguard Worker surfaceControlStats);
578*38e8c45fSAndroid Build Coastguard Worker }
579*38e8c45fSAndroid Build Coastguard Worker }
580*38e8c45fSAndroid Build Coastguard Worker
581*38e8c45fSAndroid Build Coastguard Worker for (const auto& transactionStats : listenerStats.transactionStats) {
582*38e8c45fSAndroid Build Coastguard Worker for (const auto& surfaceStats : transactionStats.surfaceStats) {
583*38e8c45fSAndroid Build Coastguard Worker // The callbackMap contains the SurfaceControl object, which we need to look up the
584*38e8c45fSAndroid Build Coastguard Worker // layerId. Since we don't know which callback contains the SurfaceControl, iterate
585*38e8c45fSAndroid Build Coastguard Worker // through all until the SC is found.
586*38e8c45fSAndroid Build Coastguard Worker int32_t layerId = -1;
587*38e8c45fSAndroid Build Coastguard Worker for (auto callbackId : transactionStats.callbackIds) {
588*38e8c45fSAndroid Build Coastguard Worker if (callbackId.type != CallbackId::Type::ON_COMPLETE) {
589*38e8c45fSAndroid Build Coastguard Worker // We only want to run the stats callback for ON_COMPLETE
590*38e8c45fSAndroid Build Coastguard Worker continue;
591*38e8c45fSAndroid Build Coastguard Worker }
592*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceControl> sc =
593*38e8c45fSAndroid Build Coastguard Worker callbacksMap[callbackId].surfaceControls[surfaceStats.surfaceControl];
594*38e8c45fSAndroid Build Coastguard Worker if (sc != nullptr) {
595*38e8c45fSAndroid Build Coastguard Worker layerId = sc->getLayerId();
596*38e8c45fSAndroid Build Coastguard Worker break;
597*38e8c45fSAndroid Build Coastguard Worker }
598*38e8c45fSAndroid Build Coastguard Worker }
599*38e8c45fSAndroid Build Coastguard Worker
600*38e8c45fSAndroid Build Coastguard Worker if (layerId != -1) {
601*38e8c45fSAndroid Build Coastguard Worker // Acquire surface stats listener lock such that we guarantee that after calling
602*38e8c45fSAndroid Build Coastguard Worker // unregister, there won't be any further callback.
603*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::recursive_mutex> lock(mSurfaceStatsListenerMutex);
604*38e8c45fSAndroid Build Coastguard Worker auto listenerRange = mSurfaceStatsListeners.equal_range(layerId);
605*38e8c45fSAndroid Build Coastguard Worker for (auto it = listenerRange.first; it != listenerRange.second; it++) {
606*38e8c45fSAndroid Build Coastguard Worker auto entry = it->second;
607*38e8c45fSAndroid Build Coastguard Worker entry.callback(entry.context, transactionStats.latchTime,
608*38e8c45fSAndroid Build Coastguard Worker transactionStats.presentFence, surfaceStats);
609*38e8c45fSAndroid Build Coastguard Worker }
610*38e8c45fSAndroid Build Coastguard Worker }
611*38e8c45fSAndroid Build Coastguard Worker }
612*38e8c45fSAndroid Build Coastguard Worker }
613*38e8c45fSAndroid Build Coastguard Worker }
614*38e8c45fSAndroid Build Coastguard Worker
onTransactionQueueStalled(const String8 & reason)615*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::onTransactionQueueStalled(const String8& reason) {
616*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<void*, std::function<void(const std::string&)>> callbackCopy;
617*38e8c45fSAndroid Build Coastguard Worker {
618*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
619*38e8c45fSAndroid Build Coastguard Worker callbackCopy = mQueueStallListeners;
620*38e8c45fSAndroid Build Coastguard Worker }
621*38e8c45fSAndroid Build Coastguard Worker for (auto const& it : callbackCopy) {
622*38e8c45fSAndroid Build Coastguard Worker it.second(reason.c_str());
623*38e8c45fSAndroid Build Coastguard Worker }
624*38e8c45fSAndroid Build Coastguard Worker }
625*38e8c45fSAndroid Build Coastguard Worker
addQueueStallListener(std::function<void (const std::string &)> stallListener,void * id)626*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::addQueueStallListener(
627*38e8c45fSAndroid Build Coastguard Worker std::function<void(const std::string&)> stallListener, void* id) {
628*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
629*38e8c45fSAndroid Build Coastguard Worker mQueueStallListeners[id] = stallListener;
630*38e8c45fSAndroid Build Coastguard Worker }
631*38e8c45fSAndroid Build Coastguard Worker
removeQueueStallListener(void * id)632*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::removeQueueStallListener(void* id) {
633*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
634*38e8c45fSAndroid Build Coastguard Worker mQueueStallListeners.erase(id);
635*38e8c45fSAndroid Build Coastguard Worker }
636*38e8c45fSAndroid Build Coastguard Worker
onReleaseBuffer(ReleaseCallbackId callbackId,sp<Fence> releaseFence,uint32_t currentMaxAcquiredBufferCount)637*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::onReleaseBuffer(ReleaseCallbackId callbackId,
638*38e8c45fSAndroid Build Coastguard Worker sp<Fence> releaseFence,
639*38e8c45fSAndroid Build Coastguard Worker uint32_t currentMaxAcquiredBufferCount) {
640*38e8c45fSAndroid Build Coastguard Worker ReleaseBufferCallback callback;
641*38e8c45fSAndroid Build Coastguard Worker {
642*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
643*38e8c45fSAndroid Build Coastguard Worker callback = popReleaseBufferCallbackLocked(callbackId);
644*38e8c45fSAndroid Build Coastguard Worker }
645*38e8c45fSAndroid Build Coastguard Worker if (!callback) {
646*38e8c45fSAndroid Build Coastguard Worker ALOGE("Could not call release buffer callback, buffer not found %s",
647*38e8c45fSAndroid Build Coastguard Worker callbackId.to_string().c_str());
648*38e8c45fSAndroid Build Coastguard Worker return;
649*38e8c45fSAndroid Build Coastguard Worker }
650*38e8c45fSAndroid Build Coastguard Worker std::optional<uint32_t> optionalMaxAcquiredBufferCount =
651*38e8c45fSAndroid Build Coastguard Worker currentMaxAcquiredBufferCount == UINT_MAX
652*38e8c45fSAndroid Build Coastguard Worker ? std::nullopt
653*38e8c45fSAndroid Build Coastguard Worker : std::make_optional<uint32_t>(currentMaxAcquiredBufferCount);
654*38e8c45fSAndroid Build Coastguard Worker callback(callbackId, releaseFence, optionalMaxAcquiredBufferCount);
655*38e8c45fSAndroid Build Coastguard Worker }
656*38e8c45fSAndroid Build Coastguard Worker
popReleaseBufferCallbackLocked(const ReleaseCallbackId & callbackId)657*38e8c45fSAndroid Build Coastguard Worker ReleaseBufferCallback TransactionCompletedListener::popReleaseBufferCallbackLocked(
658*38e8c45fSAndroid Build Coastguard Worker const ReleaseCallbackId& callbackId) {
659*38e8c45fSAndroid Build Coastguard Worker ReleaseBufferCallback callback;
660*38e8c45fSAndroid Build Coastguard Worker auto itr = mReleaseBufferCallbacks.find(callbackId);
661*38e8c45fSAndroid Build Coastguard Worker if (itr == mReleaseBufferCallbacks.end()) {
662*38e8c45fSAndroid Build Coastguard Worker return nullptr;
663*38e8c45fSAndroid Build Coastguard Worker }
664*38e8c45fSAndroid Build Coastguard Worker callback = itr->second;
665*38e8c45fSAndroid Build Coastguard Worker mReleaseBufferCallbacks.erase(itr);
666*38e8c45fSAndroid Build Coastguard Worker return callback;
667*38e8c45fSAndroid Build Coastguard Worker }
668*38e8c45fSAndroid Build Coastguard Worker
removeReleaseBufferCallback(const ReleaseCallbackId & callbackId)669*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::removeReleaseBufferCallback(
670*38e8c45fSAndroid Build Coastguard Worker const ReleaseCallbackId& callbackId) {
671*38e8c45fSAndroid Build Coastguard Worker {
672*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
673*38e8c45fSAndroid Build Coastguard Worker popReleaseBufferCallbackLocked(callbackId);
674*38e8c45fSAndroid Build Coastguard Worker }
675*38e8c45fSAndroid Build Coastguard Worker }
676*38e8c45fSAndroid Build Coastguard Worker
PresentationCallbackRAII(TransactionCompletedListener * tcl,int id)677*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::PresentationCallbackRAII::PresentationCallbackRAII(
678*38e8c45fSAndroid Build Coastguard Worker TransactionCompletedListener* tcl, int id) {
679*38e8c45fSAndroid Build Coastguard Worker mTcl = tcl;
680*38e8c45fSAndroid Build Coastguard Worker mId = id;
681*38e8c45fSAndroid Build Coastguard Worker }
682*38e8c45fSAndroid Build Coastguard Worker
~PresentationCallbackRAII()683*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::PresentationCallbackRAII::~PresentationCallbackRAII() {
684*38e8c45fSAndroid Build Coastguard Worker mTcl->clearTrustedPresentationCallback(mId);
685*38e8c45fSAndroid Build Coastguard Worker }
686*38e8c45fSAndroid Build Coastguard Worker
687*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceComposerClient::PresentationCallbackRAII>
addTrustedPresentationCallback(TrustedPresentationCallback tpc,int id,void * context)688*38e8c45fSAndroid Build Coastguard Worker TransactionCompletedListener::addTrustedPresentationCallback(TrustedPresentationCallback tpc,
689*38e8c45fSAndroid Build Coastguard Worker int id, void* context) {
690*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
691*38e8c45fSAndroid Build Coastguard Worker mTrustedPresentationCallbacks[id] =
692*38e8c45fSAndroid Build Coastguard Worker std::tuple<TrustedPresentationCallback, void*>(tpc, context);
693*38e8c45fSAndroid Build Coastguard Worker return new SurfaceComposerClient::PresentationCallbackRAII(this, id);
694*38e8c45fSAndroid Build Coastguard Worker }
695*38e8c45fSAndroid Build Coastguard Worker
clearTrustedPresentationCallback(int id)696*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::clearTrustedPresentationCallback(int id) {
697*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
698*38e8c45fSAndroid Build Coastguard Worker mTrustedPresentationCallbacks.erase(id);
699*38e8c45fSAndroid Build Coastguard Worker }
700*38e8c45fSAndroid Build Coastguard Worker
onTrustedPresentationChanged(int id,bool presentedWithinThresholds)701*38e8c45fSAndroid Build Coastguard Worker void TransactionCompletedListener::onTrustedPresentationChanged(int id,
702*38e8c45fSAndroid Build Coastguard Worker bool presentedWithinThresholds) {
703*38e8c45fSAndroid Build Coastguard Worker TrustedPresentationCallback tpc;
704*38e8c45fSAndroid Build Coastguard Worker void* context;
705*38e8c45fSAndroid Build Coastguard Worker {
706*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
707*38e8c45fSAndroid Build Coastguard Worker auto it = mTrustedPresentationCallbacks.find(id);
708*38e8c45fSAndroid Build Coastguard Worker if (it == mTrustedPresentationCallbacks.end()) {
709*38e8c45fSAndroid Build Coastguard Worker return;
710*38e8c45fSAndroid Build Coastguard Worker }
711*38e8c45fSAndroid Build Coastguard Worker std::tie(tpc, context) = it->second;
712*38e8c45fSAndroid Build Coastguard Worker }
713*38e8c45fSAndroid Build Coastguard Worker tpc(context, presentedWithinThresholds);
714*38e8c45fSAndroid Build Coastguard Worker }
715*38e8c45fSAndroid Build Coastguard Worker
716*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------
717*38e8c45fSAndroid Build Coastguard Worker
718*38e8c45fSAndroid Build Coastguard Worker void removeDeadBufferCallback(void* /*context*/, uint64_t graphicBufferId);
719*38e8c45fSAndroid Build Coastguard Worker
720*38e8c45fSAndroid Build Coastguard Worker /**
721*38e8c45fSAndroid Build Coastguard Worker * We use the BufferCache to reduce the overhead of exchanging GraphicBuffers with
722*38e8c45fSAndroid Build Coastguard Worker * the server. If we were to simply parcel the GraphicBuffer we would pay two overheads
723*38e8c45fSAndroid Build Coastguard Worker * 1. Cost of sending the FD
724*38e8c45fSAndroid Build Coastguard Worker * 2. Cost of importing the GraphicBuffer with the mapper in the receiving process.
725*38e8c45fSAndroid Build Coastguard Worker * To ease this cost we implement the following scheme of caching buffers to integers,
726*38e8c45fSAndroid Build Coastguard Worker * or said-otherwise, naming them with integers. This is the scheme known as slots in
727*38e8c45fSAndroid Build Coastguard Worker * the legacy BufferQueue system.
728*38e8c45fSAndroid Build Coastguard Worker * 1. When sending Buffers to SurfaceFlinger we look up the Buffer in the cache.
729*38e8c45fSAndroid Build Coastguard Worker * 2. If there is a cache-hit we remove the Buffer from the Transaction and instead
730*38e8c45fSAndroid Build Coastguard Worker * send the cached integer.
731*38e8c45fSAndroid Build Coastguard Worker * 3. If there is a cache miss, we cache the new buffer and send the integer
732*38e8c45fSAndroid Build Coastguard Worker * along with the Buffer, SurfaceFlinger on it's side creates a new cache
733*38e8c45fSAndroid Build Coastguard Worker * entry, and we use the integer for further communication.
734*38e8c45fSAndroid Build Coastguard Worker * A few details about lifetime:
735*38e8c45fSAndroid Build Coastguard Worker * 1. The cache evicts by LRU. The server side cache is keyed by BufferCache::getToken
736*38e8c45fSAndroid Build Coastguard Worker * which is per process Unique. The server side cache is larger than the client side
737*38e8c45fSAndroid Build Coastguard Worker * cache so that the server will never evict entries before the client.
738*38e8c45fSAndroid Build Coastguard Worker * 2. When the client evicts an entry it notifies the server via an uncacheBuffer
739*38e8c45fSAndroid Build Coastguard Worker * transaction.
740*38e8c45fSAndroid Build Coastguard Worker * 3. The client only references the Buffers by ID, and uses buffer->addDeathCallback
741*38e8c45fSAndroid Build Coastguard Worker * to auto-evict destroyed buffers.
742*38e8c45fSAndroid Build Coastguard Worker */
743*38e8c45fSAndroid Build Coastguard Worker class BufferCache : public Singleton<BufferCache> {
744*38e8c45fSAndroid Build Coastguard Worker public:
BufferCache()745*38e8c45fSAndroid Build Coastguard Worker BufferCache() : token(new BBinder()) {}
746*38e8c45fSAndroid Build Coastguard Worker
getToken()747*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> getToken() {
748*38e8c45fSAndroid Build Coastguard Worker return IInterface::asBinder(TransactionCompletedListener::getIInstance());
749*38e8c45fSAndroid Build Coastguard Worker }
750*38e8c45fSAndroid Build Coastguard Worker
getCacheId(const sp<GraphicBuffer> & buffer,uint64_t * cacheId)751*38e8c45fSAndroid Build Coastguard Worker status_t getCacheId(const sp<GraphicBuffer>& buffer, uint64_t* cacheId) {
752*38e8c45fSAndroid Build Coastguard Worker std::lock_guard<std::mutex> lock(mMutex);
753*38e8c45fSAndroid Build Coastguard Worker
754*38e8c45fSAndroid Build Coastguard Worker auto itr = mBuffers.find(buffer->getId());
755*38e8c45fSAndroid Build Coastguard Worker if (itr == mBuffers.end()) {
756*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
757*38e8c45fSAndroid Build Coastguard Worker }
758*38e8c45fSAndroid Build Coastguard Worker itr->second = getCounter();
759*38e8c45fSAndroid Build Coastguard Worker *cacheId = buffer->getId();
760*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
761*38e8c45fSAndroid Build Coastguard Worker }
762*38e8c45fSAndroid Build Coastguard Worker
cache(const sp<GraphicBuffer> & buffer,std::optional<client_cache_t> & outUncacheBuffer)763*38e8c45fSAndroid Build Coastguard Worker uint64_t cache(const sp<GraphicBuffer>& buffer,
764*38e8c45fSAndroid Build Coastguard Worker std::optional<client_cache_t>& outUncacheBuffer) {
765*38e8c45fSAndroid Build Coastguard Worker std::lock_guard<std::mutex> lock(mMutex);
766*38e8c45fSAndroid Build Coastguard Worker
767*38e8c45fSAndroid Build Coastguard Worker if (mBuffers.size() >= BUFFER_CACHE_MAX_SIZE) {
768*38e8c45fSAndroid Build Coastguard Worker outUncacheBuffer = findLeastRecentlyUsedBuffer();
769*38e8c45fSAndroid Build Coastguard Worker mBuffers.erase(outUncacheBuffer->id);
770*38e8c45fSAndroid Build Coastguard Worker }
771*38e8c45fSAndroid Build Coastguard Worker
772*38e8c45fSAndroid Build Coastguard Worker buffer->addDeathCallback(removeDeadBufferCallback, nullptr);
773*38e8c45fSAndroid Build Coastguard Worker
774*38e8c45fSAndroid Build Coastguard Worker mBuffers[buffer->getId()] = getCounter();
775*38e8c45fSAndroid Build Coastguard Worker return buffer->getId();
776*38e8c45fSAndroid Build Coastguard Worker }
777*38e8c45fSAndroid Build Coastguard Worker
uncache(uint64_t cacheId)778*38e8c45fSAndroid Build Coastguard Worker void uncache(uint64_t cacheId) {
779*38e8c45fSAndroid Build Coastguard Worker std::lock_guard<std::mutex> lock(mMutex);
780*38e8c45fSAndroid Build Coastguard Worker if (mBuffers.erase(cacheId)) {
781*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::doUncacheBufferTransaction(cacheId);
782*38e8c45fSAndroid Build Coastguard Worker }
783*38e8c45fSAndroid Build Coastguard Worker }
784*38e8c45fSAndroid Build Coastguard Worker
785*38e8c45fSAndroid Build Coastguard Worker private:
findLeastRecentlyUsedBuffer()786*38e8c45fSAndroid Build Coastguard Worker client_cache_t findLeastRecentlyUsedBuffer() REQUIRES(mMutex) {
787*38e8c45fSAndroid Build Coastguard Worker auto itr = mBuffers.begin();
788*38e8c45fSAndroid Build Coastguard Worker uint64_t minCounter = itr->second;
789*38e8c45fSAndroid Build Coastguard Worker auto minBuffer = itr;
790*38e8c45fSAndroid Build Coastguard Worker itr++;
791*38e8c45fSAndroid Build Coastguard Worker
792*38e8c45fSAndroid Build Coastguard Worker while (itr != mBuffers.end()) {
793*38e8c45fSAndroid Build Coastguard Worker uint64_t counter = itr->second;
794*38e8c45fSAndroid Build Coastguard Worker if (counter < minCounter) {
795*38e8c45fSAndroid Build Coastguard Worker minCounter = counter;
796*38e8c45fSAndroid Build Coastguard Worker minBuffer = itr;
797*38e8c45fSAndroid Build Coastguard Worker }
798*38e8c45fSAndroid Build Coastguard Worker itr++;
799*38e8c45fSAndroid Build Coastguard Worker }
800*38e8c45fSAndroid Build Coastguard Worker
801*38e8c45fSAndroid Build Coastguard Worker return {.token = getToken(), .id = minBuffer->first};
802*38e8c45fSAndroid Build Coastguard Worker }
803*38e8c45fSAndroid Build Coastguard Worker
getCounter()804*38e8c45fSAndroid Build Coastguard Worker uint64_t getCounter() REQUIRES(mMutex) {
805*38e8c45fSAndroid Build Coastguard Worker static uint64_t counter = 0;
806*38e8c45fSAndroid Build Coastguard Worker return counter++;
807*38e8c45fSAndroid Build Coastguard Worker }
808*38e8c45fSAndroid Build Coastguard Worker
809*38e8c45fSAndroid Build Coastguard Worker std::mutex mMutex;
810*38e8c45fSAndroid Build Coastguard Worker std::map<uint64_t /*Cache id*/, uint64_t /*counter*/> mBuffers GUARDED_BY(mMutex);
811*38e8c45fSAndroid Build Coastguard Worker
812*38e8c45fSAndroid Build Coastguard Worker // Used by ISurfaceComposer to identify which process is sending the cached buffer.
813*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> token;
814*38e8c45fSAndroid Build Coastguard Worker };
815*38e8c45fSAndroid Build Coastguard Worker
816*38e8c45fSAndroid Build Coastguard Worker ANDROID_SINGLETON_STATIC_INSTANCE(BufferCache);
817*38e8c45fSAndroid Build Coastguard Worker
removeDeadBufferCallback(void *,uint64_t graphicBufferId)818*38e8c45fSAndroid Build Coastguard Worker void removeDeadBufferCallback(void* /*context*/, uint64_t graphicBufferId) {
819*38e8c45fSAndroid Build Coastguard Worker // GraphicBuffer id's are used as the cache ids.
820*38e8c45fSAndroid Build Coastguard Worker BufferCache::getInstance().uncache(graphicBufferId);
821*38e8c45fSAndroid Build Coastguard Worker }
822*38e8c45fSAndroid Build Coastguard Worker
823*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------
824*38e8c45fSAndroid Build Coastguard Worker
Transaction()825*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction::Transaction() {
826*38e8c45fSAndroid Build Coastguard Worker mId = generateId();
827*38e8c45fSAndroid Build Coastguard Worker mTransactionCompletedListener = TransactionCompletedListener::getInstance();
828*38e8c45fSAndroid Build Coastguard Worker }
829*38e8c45fSAndroid Build Coastguard Worker
Transaction(const Transaction & other)830*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction::Transaction(const Transaction& other)
831*38e8c45fSAndroid Build Coastguard Worker : mId(other.mId),
832*38e8c45fSAndroid Build Coastguard Worker mAnimation(other.mAnimation),
833*38e8c45fSAndroid Build Coastguard Worker mEarlyWakeupStart(other.mEarlyWakeupStart),
834*38e8c45fSAndroid Build Coastguard Worker mEarlyWakeupEnd(other.mEarlyWakeupEnd),
835*38e8c45fSAndroid Build Coastguard Worker mMayContainBuffer(other.mMayContainBuffer),
836*38e8c45fSAndroid Build Coastguard Worker mDesiredPresentTime(other.mDesiredPresentTime),
837*38e8c45fSAndroid Build Coastguard Worker mIsAutoTimestamp(other.mIsAutoTimestamp),
838*38e8c45fSAndroid Build Coastguard Worker mFrameTimelineInfo(other.mFrameTimelineInfo),
839*38e8c45fSAndroid Build Coastguard Worker mApplyToken(other.mApplyToken) {
840*38e8c45fSAndroid Build Coastguard Worker mDisplayStates = other.mDisplayStates;
841*38e8c45fSAndroid Build Coastguard Worker mComposerStates = other.mComposerStates;
842*38e8c45fSAndroid Build Coastguard Worker mInputWindowCommands = other.mInputWindowCommands;
843*38e8c45fSAndroid Build Coastguard Worker mListenerCallbacks = other.mListenerCallbacks;
844*38e8c45fSAndroid Build Coastguard Worker mTransactionCompletedListener = TransactionCompletedListener::getInstance();
845*38e8c45fSAndroid Build Coastguard Worker }
846*38e8c45fSAndroid Build Coastguard Worker
sanitize(int pid,int uid)847*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::sanitize(int pid, int uid) {
848*38e8c45fSAndroid Build Coastguard Worker uint32_t permissions = LayerStatePermissions::getTransactionPermissions(pid, uid);
849*38e8c45fSAndroid Build Coastguard Worker for (auto & [handle, composerState] : mComposerStates) {
850*38e8c45fSAndroid Build Coastguard Worker composerState.state.sanitize(permissions);
851*38e8c45fSAndroid Build Coastguard Worker }
852*38e8c45fSAndroid Build Coastguard Worker if (!mInputWindowCommands.empty() &&
853*38e8c45fSAndroid Build Coastguard Worker (permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER) == 0) {
854*38e8c45fSAndroid Build Coastguard Worker ALOGE("Only privileged callers are allowed to send input commands.");
855*38e8c45fSAndroid Build Coastguard Worker mInputWindowCommands.clear();
856*38e8c45fSAndroid Build Coastguard Worker }
857*38e8c45fSAndroid Build Coastguard Worker }
858*38e8c45fSAndroid Build Coastguard Worker
859*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<SurfaceComposerClient::Transaction>
createFromParcel(const Parcel * parcel)860*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction::createFromParcel(const Parcel* parcel) {
861*38e8c45fSAndroid Build Coastguard Worker auto transaction = std::make_unique<Transaction>();
862*38e8c45fSAndroid Build Coastguard Worker if (transaction->readFromParcel(parcel) == NO_ERROR) {
863*38e8c45fSAndroid Build Coastguard Worker return transaction;
864*38e8c45fSAndroid Build Coastguard Worker }
865*38e8c45fSAndroid Build Coastguard Worker return nullptr;
866*38e8c45fSAndroid Build Coastguard Worker }
867*38e8c45fSAndroid Build Coastguard Worker
868*38e8c45fSAndroid Build Coastguard Worker
readFromParcel(const Parcel * parcel)869*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel) {
870*38e8c45fSAndroid Build Coastguard Worker const uint64_t transactionId = parcel->readUint64();
871*38e8c45fSAndroid Build Coastguard Worker const bool animation = parcel->readBool();
872*38e8c45fSAndroid Build Coastguard Worker const bool earlyWakeupStart = parcel->readBool();
873*38e8c45fSAndroid Build Coastguard Worker const bool earlyWakeupEnd = parcel->readBool();
874*38e8c45fSAndroid Build Coastguard Worker const int64_t desiredPresentTime = parcel->readInt64();
875*38e8c45fSAndroid Build Coastguard Worker const bool isAutoTimestamp = parcel->readBool();
876*38e8c45fSAndroid Build Coastguard Worker const bool logCallPoints = parcel->readBool();
877*38e8c45fSAndroid Build Coastguard Worker FrameTimelineInfo frameTimelineInfo;
878*38e8c45fSAndroid Build Coastguard Worker frameTimelineInfo.readFromParcel(parcel);
879*38e8c45fSAndroid Build Coastguard Worker
880*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> applyToken;
881*38e8c45fSAndroid Build Coastguard Worker parcel->readNullableStrongBinder(&applyToken);
882*38e8c45fSAndroid Build Coastguard Worker size_t count = static_cast<size_t>(parcel->readUint32());
883*38e8c45fSAndroid Build Coastguard Worker if (count > parcel->dataSize()) {
884*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
885*38e8c45fSAndroid Build Coastguard Worker }
886*38e8c45fSAndroid Build Coastguard Worker SortedVector<DisplayState> displayStates;
887*38e8c45fSAndroid Build Coastguard Worker displayStates.setCapacity(count);
888*38e8c45fSAndroid Build Coastguard Worker for (size_t i = 0; i < count; i++) {
889*38e8c45fSAndroid Build Coastguard Worker DisplayState displayState;
890*38e8c45fSAndroid Build Coastguard Worker if (displayState.read(*parcel) == BAD_VALUE) {
891*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
892*38e8c45fSAndroid Build Coastguard Worker }
893*38e8c45fSAndroid Build Coastguard Worker displayStates.add(displayState);
894*38e8c45fSAndroid Build Coastguard Worker }
895*38e8c45fSAndroid Build Coastguard Worker
896*38e8c45fSAndroid Build Coastguard Worker count = static_cast<size_t>(parcel->readUint32());
897*38e8c45fSAndroid Build Coastguard Worker if (count > parcel->dataSize()) {
898*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
899*38e8c45fSAndroid Build Coastguard Worker }
900*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> listenerCallbacks;
901*38e8c45fSAndroid Build Coastguard Worker listenerCallbacks.reserve(count);
902*38e8c45fSAndroid Build Coastguard Worker for (size_t i = 0; i < count; i++) {
903*38e8c45fSAndroid Build Coastguard Worker sp<ITransactionCompletedListener> listener =
904*38e8c45fSAndroid Build Coastguard Worker interface_cast<ITransactionCompletedListener>(parcel->readStrongBinder());
905*38e8c45fSAndroid Build Coastguard Worker size_t numCallbackIds = parcel->readUint32();
906*38e8c45fSAndroid Build Coastguard Worker if (numCallbackIds > parcel->dataSize()) {
907*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
908*38e8c45fSAndroid Build Coastguard Worker }
909*38e8c45fSAndroid Build Coastguard Worker for (size_t j = 0; j < numCallbackIds; j++) {
910*38e8c45fSAndroid Build Coastguard Worker CallbackId id;
911*38e8c45fSAndroid Build Coastguard Worker parcel->readParcelable(&id);
912*38e8c45fSAndroid Build Coastguard Worker listenerCallbacks[listener].callbackIds.insert(id);
913*38e8c45fSAndroid Build Coastguard Worker }
914*38e8c45fSAndroid Build Coastguard Worker size_t numSurfaces = parcel->readUint32();
915*38e8c45fSAndroid Build Coastguard Worker if (numSurfaces > parcel->dataSize()) {
916*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
917*38e8c45fSAndroid Build Coastguard Worker }
918*38e8c45fSAndroid Build Coastguard Worker for (size_t j = 0; j < numSurfaces; j++) {
919*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceControl> surface;
920*38e8c45fSAndroid Build Coastguard Worker SAFE_PARCEL(SurfaceControl::readFromParcel, *parcel, &surface);
921*38e8c45fSAndroid Build Coastguard Worker listenerCallbacks[listener].surfaceControls.insert(surface);
922*38e8c45fSAndroid Build Coastguard Worker }
923*38e8c45fSAndroid Build Coastguard Worker }
924*38e8c45fSAndroid Build Coastguard Worker
925*38e8c45fSAndroid Build Coastguard Worker count = static_cast<size_t>(parcel->readUint32());
926*38e8c45fSAndroid Build Coastguard Worker if (count > parcel->dataSize()) {
927*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
928*38e8c45fSAndroid Build Coastguard Worker }
929*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<sp<IBinder>, ComposerState, IBinderHash> composerStates;
930*38e8c45fSAndroid Build Coastguard Worker composerStates.reserve(count);
931*38e8c45fSAndroid Build Coastguard Worker for (size_t i = 0; i < count; i++) {
932*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> surfaceControlHandle;
933*38e8c45fSAndroid Build Coastguard Worker SAFE_PARCEL(parcel->readStrongBinder, &surfaceControlHandle);
934*38e8c45fSAndroid Build Coastguard Worker
935*38e8c45fSAndroid Build Coastguard Worker ComposerState composerState;
936*38e8c45fSAndroid Build Coastguard Worker if (composerState.read(*parcel) == BAD_VALUE) {
937*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
938*38e8c45fSAndroid Build Coastguard Worker }
939*38e8c45fSAndroid Build Coastguard Worker composerStates[surfaceControlHandle] = composerState;
940*38e8c45fSAndroid Build Coastguard Worker }
941*38e8c45fSAndroid Build Coastguard Worker
942*38e8c45fSAndroid Build Coastguard Worker InputWindowCommands inputWindowCommands;
943*38e8c45fSAndroid Build Coastguard Worker inputWindowCommands.read(*parcel);
944*38e8c45fSAndroid Build Coastguard Worker
945*38e8c45fSAndroid Build Coastguard Worker count = static_cast<size_t>(parcel->readUint32());
946*38e8c45fSAndroid Build Coastguard Worker if (count > parcel->dataSize()) {
947*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
948*38e8c45fSAndroid Build Coastguard Worker }
949*38e8c45fSAndroid Build Coastguard Worker std::vector<client_cache_t> uncacheBuffers(count);
950*38e8c45fSAndroid Build Coastguard Worker for (size_t i = 0; i < count; i++) {
951*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> tmpBinder;
952*38e8c45fSAndroid Build Coastguard Worker SAFE_PARCEL(parcel->readStrongBinder, &tmpBinder);
953*38e8c45fSAndroid Build Coastguard Worker uncacheBuffers[i].token = tmpBinder;
954*38e8c45fSAndroid Build Coastguard Worker SAFE_PARCEL(parcel->readUint64, &uncacheBuffers[i].id);
955*38e8c45fSAndroid Build Coastguard Worker }
956*38e8c45fSAndroid Build Coastguard Worker
957*38e8c45fSAndroid Build Coastguard Worker count = static_cast<size_t>(parcel->readUint32());
958*38e8c45fSAndroid Build Coastguard Worker if (count > parcel->dataSize()) {
959*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
960*38e8c45fSAndroid Build Coastguard Worker }
961*38e8c45fSAndroid Build Coastguard Worker std::vector<uint64_t> mergedTransactionIds(count);
962*38e8c45fSAndroid Build Coastguard Worker for (size_t i = 0; i < count; i++) {
963*38e8c45fSAndroid Build Coastguard Worker SAFE_PARCEL(parcel->readUint64, &mergedTransactionIds[i]);
964*38e8c45fSAndroid Build Coastguard Worker }
965*38e8c45fSAndroid Build Coastguard Worker
966*38e8c45fSAndroid Build Coastguard Worker // Parsing was successful. Update the object.
967*38e8c45fSAndroid Build Coastguard Worker mId = transactionId;
968*38e8c45fSAndroid Build Coastguard Worker mAnimation = animation;
969*38e8c45fSAndroid Build Coastguard Worker mEarlyWakeupStart = earlyWakeupStart;
970*38e8c45fSAndroid Build Coastguard Worker mEarlyWakeupEnd = earlyWakeupEnd;
971*38e8c45fSAndroid Build Coastguard Worker mDesiredPresentTime = desiredPresentTime;
972*38e8c45fSAndroid Build Coastguard Worker mIsAutoTimestamp = isAutoTimestamp;
973*38e8c45fSAndroid Build Coastguard Worker mFrameTimelineInfo = frameTimelineInfo;
974*38e8c45fSAndroid Build Coastguard Worker mDisplayStates = displayStates;
975*38e8c45fSAndroid Build Coastguard Worker mListenerCallbacks = listenerCallbacks;
976*38e8c45fSAndroid Build Coastguard Worker mComposerStates = composerStates;
977*38e8c45fSAndroid Build Coastguard Worker mInputWindowCommands = inputWindowCommands;
978*38e8c45fSAndroid Build Coastguard Worker mApplyToken = applyToken;
979*38e8c45fSAndroid Build Coastguard Worker mUncacheBuffers = std::move(uncacheBuffers);
980*38e8c45fSAndroid Build Coastguard Worker mMergedTransactionIds = std::move(mergedTransactionIds);
981*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
982*38e8c45fSAndroid Build Coastguard Worker }
983*38e8c45fSAndroid Build Coastguard Worker
writeToParcel(Parcel * parcel) const984*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const {
985*38e8c45fSAndroid Build Coastguard Worker // If we write the Transaction to a parcel, we want to ensure the Buffers are cached
986*38e8c45fSAndroid Build Coastguard Worker // before crossing the IPC boundary. Otherwise the receiving party will cache the buffers
987*38e8c45fSAndroid Build Coastguard Worker // but is unlikely to use them again as they are owned by the other process.
988*38e8c45fSAndroid Build Coastguard Worker // You may be asking yourself, is this const cast safe? Const cast is safe up
989*38e8c45fSAndroid Build Coastguard Worker // until the point where you try and write to an object that was originally const at which
990*38e8c45fSAndroid Build Coastguard Worker // point we enter undefined behavior. In this case we are safe though, because there are
991*38e8c45fSAndroid Build Coastguard Worker // two possibilities:
992*38e8c45fSAndroid Build Coastguard Worker // 1. The SurfaceComposerClient::Transaction was originally non-const. Safe.
993*38e8c45fSAndroid Build Coastguard Worker // 2. It was originall const! In this case not only was it useless, but it by definition
994*38e8c45fSAndroid Build Coastguard Worker // contains no composer states and so cacheBuffers will not perform any writes.
995*38e8c45fSAndroid Build Coastguard Worker
996*38e8c45fSAndroid Build Coastguard Worker const_cast<SurfaceComposerClient::Transaction*>(this)->cacheBuffers();
997*38e8c45fSAndroid Build Coastguard Worker
998*38e8c45fSAndroid Build Coastguard Worker parcel->writeUint64(mId);
999*38e8c45fSAndroid Build Coastguard Worker parcel->writeBool(mAnimation);
1000*38e8c45fSAndroid Build Coastguard Worker parcel->writeBool(mEarlyWakeupStart);
1001*38e8c45fSAndroid Build Coastguard Worker parcel->writeBool(mEarlyWakeupEnd);
1002*38e8c45fSAndroid Build Coastguard Worker parcel->writeInt64(mDesiredPresentTime);
1003*38e8c45fSAndroid Build Coastguard Worker parcel->writeBool(mIsAutoTimestamp);
1004*38e8c45fSAndroid Build Coastguard Worker parcel->writeBool(mLogCallPoints);
1005*38e8c45fSAndroid Build Coastguard Worker mFrameTimelineInfo.writeToParcel(parcel);
1006*38e8c45fSAndroid Build Coastguard Worker parcel->writeStrongBinder(mApplyToken);
1007*38e8c45fSAndroid Build Coastguard Worker parcel->writeUint32(static_cast<uint32_t>(mDisplayStates.size()));
1008*38e8c45fSAndroid Build Coastguard Worker for (auto const& displayState : mDisplayStates) {
1009*38e8c45fSAndroid Build Coastguard Worker displayState.write(*parcel);
1010*38e8c45fSAndroid Build Coastguard Worker }
1011*38e8c45fSAndroid Build Coastguard Worker
1012*38e8c45fSAndroid Build Coastguard Worker parcel->writeUint32(static_cast<uint32_t>(mListenerCallbacks.size()));
1013*38e8c45fSAndroid Build Coastguard Worker for (auto const& [listener, callbackInfo] : mListenerCallbacks) {
1014*38e8c45fSAndroid Build Coastguard Worker parcel->writeStrongBinder(ITransactionCompletedListener::asBinder(listener));
1015*38e8c45fSAndroid Build Coastguard Worker parcel->writeUint32(static_cast<uint32_t>(callbackInfo.callbackIds.size()));
1016*38e8c45fSAndroid Build Coastguard Worker for (auto callbackId : callbackInfo.callbackIds) {
1017*38e8c45fSAndroid Build Coastguard Worker parcel->writeParcelable(callbackId);
1018*38e8c45fSAndroid Build Coastguard Worker }
1019*38e8c45fSAndroid Build Coastguard Worker parcel->writeUint32(static_cast<uint32_t>(callbackInfo.surfaceControls.size()));
1020*38e8c45fSAndroid Build Coastguard Worker for (auto surfaceControl : callbackInfo.surfaceControls) {
1021*38e8c45fSAndroid Build Coastguard Worker SAFE_PARCEL(surfaceControl->writeToParcel, *parcel);
1022*38e8c45fSAndroid Build Coastguard Worker }
1023*38e8c45fSAndroid Build Coastguard Worker }
1024*38e8c45fSAndroid Build Coastguard Worker
1025*38e8c45fSAndroid Build Coastguard Worker parcel->writeUint32(static_cast<uint32_t>(mComposerStates.size()));
1026*38e8c45fSAndroid Build Coastguard Worker for (auto const& [handle, composerState] : mComposerStates) {
1027*38e8c45fSAndroid Build Coastguard Worker SAFE_PARCEL(parcel->writeStrongBinder, handle);
1028*38e8c45fSAndroid Build Coastguard Worker composerState.write(*parcel);
1029*38e8c45fSAndroid Build Coastguard Worker }
1030*38e8c45fSAndroid Build Coastguard Worker
1031*38e8c45fSAndroid Build Coastguard Worker mInputWindowCommands.write(*parcel);
1032*38e8c45fSAndroid Build Coastguard Worker
1033*38e8c45fSAndroid Build Coastguard Worker SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mUncacheBuffers.size()));
1034*38e8c45fSAndroid Build Coastguard Worker for (const client_cache_t& uncacheBuffer : mUncacheBuffers) {
1035*38e8c45fSAndroid Build Coastguard Worker SAFE_PARCEL(parcel->writeStrongBinder, uncacheBuffer.token.promote());
1036*38e8c45fSAndroid Build Coastguard Worker SAFE_PARCEL(parcel->writeUint64, uncacheBuffer.id);
1037*38e8c45fSAndroid Build Coastguard Worker }
1038*38e8c45fSAndroid Build Coastguard Worker
1039*38e8c45fSAndroid Build Coastguard Worker SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mMergedTransactionIds.size()));
1040*38e8c45fSAndroid Build Coastguard Worker for (auto mergedTransactionId : mMergedTransactionIds) {
1041*38e8c45fSAndroid Build Coastguard Worker SAFE_PARCEL(parcel->writeUint64, mergedTransactionId);
1042*38e8c45fSAndroid Build Coastguard Worker }
1043*38e8c45fSAndroid Build Coastguard Worker
1044*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
1045*38e8c45fSAndroid Build Coastguard Worker }
1046*38e8c45fSAndroid Build Coastguard Worker
releaseBufferIfOverwriting(const layer_state_t & state)1047*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::releaseBufferIfOverwriting(const layer_state_t& state) {
1048*38e8c45fSAndroid Build Coastguard Worker if (!(state.what & layer_state_t::eBufferChanged) || !state.bufferData->hasBuffer()) {
1049*38e8c45fSAndroid Build Coastguard Worker return;
1050*38e8c45fSAndroid Build Coastguard Worker }
1051*38e8c45fSAndroid Build Coastguard Worker
1052*38e8c45fSAndroid Build Coastguard Worker auto listener = state.bufferData->releaseBufferListener;
1053*38e8c45fSAndroid Build Coastguard Worker sp<Fence> fence =
1054*38e8c45fSAndroid Build Coastguard Worker state.bufferData->acquireFence ? state.bufferData->acquireFence : Fence::NO_FENCE;
1055*38e8c45fSAndroid Build Coastguard Worker if (state.bufferData->releaseBufferEndpoint ==
1056*38e8c45fSAndroid Build Coastguard Worker IInterface::asBinder(TransactionCompletedListener::getIInstance())) {
1057*38e8c45fSAndroid Build Coastguard Worker // if the callback is in process, run on a different thread to avoid any lock contigency
1058*38e8c45fSAndroid Build Coastguard Worker // issues in the client.
1059*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::getDefault()
1060*38e8c45fSAndroid Build Coastguard Worker ->mReleaseCallbackThread
1061*38e8c45fSAndroid Build Coastguard Worker .addReleaseCallback(state.bufferData->generateReleaseCallbackId(), fence);
1062*38e8c45fSAndroid Build Coastguard Worker } else {
1063*38e8c45fSAndroid Build Coastguard Worker listener->onReleaseBuffer(state.bufferData->generateReleaseCallbackId(), fence, UINT_MAX);
1064*38e8c45fSAndroid Build Coastguard Worker }
1065*38e8c45fSAndroid Build Coastguard Worker }
1066*38e8c45fSAndroid Build Coastguard Worker
merge(Transaction && other)1067*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Transaction&& other) {
1068*38e8c45fSAndroid Build Coastguard Worker while (mMergedTransactionIds.size() + other.mMergedTransactionIds.size() >
1069*38e8c45fSAndroid Build Coastguard Worker MAX_MERGE_HISTORY_LENGTH - 1 &&
1070*38e8c45fSAndroid Build Coastguard Worker mMergedTransactionIds.size() > 0) {
1071*38e8c45fSAndroid Build Coastguard Worker mMergedTransactionIds.pop_back();
1072*38e8c45fSAndroid Build Coastguard Worker }
1073*38e8c45fSAndroid Build Coastguard Worker if (other.mMergedTransactionIds.size() == MAX_MERGE_HISTORY_LENGTH) {
1074*38e8c45fSAndroid Build Coastguard Worker mMergedTransactionIds.insert(mMergedTransactionIds.begin(),
1075*38e8c45fSAndroid Build Coastguard Worker other.mMergedTransactionIds.begin(),
1076*38e8c45fSAndroid Build Coastguard Worker other.mMergedTransactionIds.end() - 1);
1077*38e8c45fSAndroid Build Coastguard Worker } else if (other.mMergedTransactionIds.size() > 0u) {
1078*38e8c45fSAndroid Build Coastguard Worker mMergedTransactionIds.insert(mMergedTransactionIds.begin(),
1079*38e8c45fSAndroid Build Coastguard Worker other.mMergedTransactionIds.begin(),
1080*38e8c45fSAndroid Build Coastguard Worker other.mMergedTransactionIds.end());
1081*38e8c45fSAndroid Build Coastguard Worker }
1082*38e8c45fSAndroid Build Coastguard Worker mMergedTransactionIds.insert(mMergedTransactionIds.begin(), other.mId);
1083*38e8c45fSAndroid Build Coastguard Worker
1084*38e8c45fSAndroid Build Coastguard Worker for (auto const& [handle, composerState] : other.mComposerStates) {
1085*38e8c45fSAndroid Build Coastguard Worker if (mComposerStates.count(handle) == 0) {
1086*38e8c45fSAndroid Build Coastguard Worker mComposerStates[handle] = composerState;
1087*38e8c45fSAndroid Build Coastguard Worker } else {
1088*38e8c45fSAndroid Build Coastguard Worker if (composerState.state.what & layer_state_t::eBufferChanged) {
1089*38e8c45fSAndroid Build Coastguard Worker releaseBufferIfOverwriting(mComposerStates[handle].state);
1090*38e8c45fSAndroid Build Coastguard Worker }
1091*38e8c45fSAndroid Build Coastguard Worker mComposerStates[handle].state.merge(composerState.state);
1092*38e8c45fSAndroid Build Coastguard Worker }
1093*38e8c45fSAndroid Build Coastguard Worker }
1094*38e8c45fSAndroid Build Coastguard Worker
1095*38e8c45fSAndroid Build Coastguard Worker for (auto const& state : other.mDisplayStates) {
1096*38e8c45fSAndroid Build Coastguard Worker ssize_t index = mDisplayStates.indexOf(state);
1097*38e8c45fSAndroid Build Coastguard Worker if (index < 0) {
1098*38e8c45fSAndroid Build Coastguard Worker mDisplayStates.add(state);
1099*38e8c45fSAndroid Build Coastguard Worker } else {
1100*38e8c45fSAndroid Build Coastguard Worker mDisplayStates.editItemAt(static_cast<size_t>(index)).merge(state);
1101*38e8c45fSAndroid Build Coastguard Worker }
1102*38e8c45fSAndroid Build Coastguard Worker }
1103*38e8c45fSAndroid Build Coastguard Worker
1104*38e8c45fSAndroid Build Coastguard Worker for (const auto& [listener, callbackInfo] : other.mListenerCallbacks) {
1105*38e8c45fSAndroid Build Coastguard Worker auto& [callbackIds, surfaceControls] = callbackInfo;
1106*38e8c45fSAndroid Build Coastguard Worker mListenerCallbacks[listener].callbackIds.insert(std::make_move_iterator(
1107*38e8c45fSAndroid Build Coastguard Worker callbackIds.begin()),
1108*38e8c45fSAndroid Build Coastguard Worker std::make_move_iterator(callbackIds.end()));
1109*38e8c45fSAndroid Build Coastguard Worker
1110*38e8c45fSAndroid Build Coastguard Worker mListenerCallbacks[listener].surfaceControls.insert(surfaceControls.begin(),
1111*38e8c45fSAndroid Build Coastguard Worker surfaceControls.end());
1112*38e8c45fSAndroid Build Coastguard Worker
1113*38e8c45fSAndroid Build Coastguard Worker auto& currentProcessCallbackInfo =
1114*38e8c45fSAndroid Build Coastguard Worker mListenerCallbacks[TransactionCompletedListener::getIInstance()];
1115*38e8c45fSAndroid Build Coastguard Worker currentProcessCallbackInfo.surfaceControls
1116*38e8c45fSAndroid Build Coastguard Worker .insert(std::make_move_iterator(surfaceControls.begin()),
1117*38e8c45fSAndroid Build Coastguard Worker std::make_move_iterator(surfaceControls.end()));
1118*38e8c45fSAndroid Build Coastguard Worker
1119*38e8c45fSAndroid Build Coastguard Worker // register all surface controls for all callbackIds for this listener that is merging
1120*38e8c45fSAndroid Build Coastguard Worker for (const auto& surfaceControl : currentProcessCallbackInfo.surfaceControls) {
1121*38e8c45fSAndroid Build Coastguard Worker mTransactionCompletedListener
1122*38e8c45fSAndroid Build Coastguard Worker ->addSurfaceControlToCallbacks(surfaceControl,
1123*38e8c45fSAndroid Build Coastguard Worker currentProcessCallbackInfo.callbackIds);
1124*38e8c45fSAndroid Build Coastguard Worker }
1125*38e8c45fSAndroid Build Coastguard Worker }
1126*38e8c45fSAndroid Build Coastguard Worker
1127*38e8c45fSAndroid Build Coastguard Worker for (const auto& cacheId : other.mUncacheBuffers) {
1128*38e8c45fSAndroid Build Coastguard Worker mUncacheBuffers.push_back(cacheId);
1129*38e8c45fSAndroid Build Coastguard Worker }
1130*38e8c45fSAndroid Build Coastguard Worker
1131*38e8c45fSAndroid Build Coastguard Worker mInputWindowCommands.merge(other.mInputWindowCommands);
1132*38e8c45fSAndroid Build Coastguard Worker
1133*38e8c45fSAndroid Build Coastguard Worker mMayContainBuffer |= other.mMayContainBuffer;
1134*38e8c45fSAndroid Build Coastguard Worker mEarlyWakeupStart = mEarlyWakeupStart || other.mEarlyWakeupStart;
1135*38e8c45fSAndroid Build Coastguard Worker mEarlyWakeupEnd = mEarlyWakeupEnd || other.mEarlyWakeupEnd;
1136*38e8c45fSAndroid Build Coastguard Worker mApplyToken = other.mApplyToken;
1137*38e8c45fSAndroid Build Coastguard Worker
1138*38e8c45fSAndroid Build Coastguard Worker mergeFrameTimelineInfo(mFrameTimelineInfo, other.mFrameTimelineInfo);
1139*38e8c45fSAndroid Build Coastguard Worker
1140*38e8c45fSAndroid Build Coastguard Worker mLogCallPoints |= other.mLogCallPoints;
1141*38e8c45fSAndroid Build Coastguard Worker if (mLogCallPoints) {
1142*38e8c45fSAndroid Build Coastguard Worker ALOG(LOG_DEBUG, LOG_SURFACE_CONTROL_REGISTRY,
1143*38e8c45fSAndroid Build Coastguard Worker "Transaction %" PRIu64 " merged with transaction %" PRIu64, other.getId(), mId);
1144*38e8c45fSAndroid Build Coastguard Worker }
1145*38e8c45fSAndroid Build Coastguard Worker
1146*38e8c45fSAndroid Build Coastguard Worker other.clear();
1147*38e8c45fSAndroid Build Coastguard Worker return *this;
1148*38e8c45fSAndroid Build Coastguard Worker }
1149*38e8c45fSAndroid Build Coastguard Worker
clear()1150*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::clear() {
1151*38e8c45fSAndroid Build Coastguard Worker mComposerStates.clear();
1152*38e8c45fSAndroid Build Coastguard Worker mDisplayStates.clear();
1153*38e8c45fSAndroid Build Coastguard Worker mListenerCallbacks.clear();
1154*38e8c45fSAndroid Build Coastguard Worker mInputWindowCommands.clear();
1155*38e8c45fSAndroid Build Coastguard Worker mUncacheBuffers.clear();
1156*38e8c45fSAndroid Build Coastguard Worker mMayContainBuffer = false;
1157*38e8c45fSAndroid Build Coastguard Worker mAnimation = false;
1158*38e8c45fSAndroid Build Coastguard Worker mEarlyWakeupStart = false;
1159*38e8c45fSAndroid Build Coastguard Worker mEarlyWakeupEnd = false;
1160*38e8c45fSAndroid Build Coastguard Worker mDesiredPresentTime = 0;
1161*38e8c45fSAndroid Build Coastguard Worker mIsAutoTimestamp = true;
1162*38e8c45fSAndroid Build Coastguard Worker mFrameTimelineInfo = {};
1163*38e8c45fSAndroid Build Coastguard Worker mApplyToken = nullptr;
1164*38e8c45fSAndroid Build Coastguard Worker mMergedTransactionIds.clear();
1165*38e8c45fSAndroid Build Coastguard Worker mLogCallPoints = false;
1166*38e8c45fSAndroid Build Coastguard Worker }
1167*38e8c45fSAndroid Build Coastguard Worker
getId()1168*38e8c45fSAndroid Build Coastguard Worker uint64_t SurfaceComposerClient::Transaction::getId() {
1169*38e8c45fSAndroid Build Coastguard Worker return mId;
1170*38e8c45fSAndroid Build Coastguard Worker }
1171*38e8c45fSAndroid Build Coastguard Worker
getMergedTransactionIds()1172*38e8c45fSAndroid Build Coastguard Worker std::vector<uint64_t> SurfaceComposerClient::Transaction::getMergedTransactionIds() {
1173*38e8c45fSAndroid Build Coastguard Worker return mMergedTransactionIds;
1174*38e8c45fSAndroid Build Coastguard Worker }
1175*38e8c45fSAndroid Build Coastguard Worker
doUncacheBufferTransaction(uint64_t cacheId)1176*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::doUncacheBufferTransaction(uint64_t cacheId) {
1177*38e8c45fSAndroid Build Coastguard Worker sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1178*38e8c45fSAndroid Build Coastguard Worker
1179*38e8c45fSAndroid Build Coastguard Worker client_cache_t uncacheBuffer;
1180*38e8c45fSAndroid Build Coastguard Worker uncacheBuffer.token = BufferCache::getInstance().getToken();
1181*38e8c45fSAndroid Build Coastguard Worker uncacheBuffer.id = cacheId;
1182*38e8c45fSAndroid Build Coastguard Worker Vector<ComposerState> composerStates;
1183*38e8c45fSAndroid Build Coastguard Worker Vector<DisplayState> displayStates;
1184*38e8c45fSAndroid Build Coastguard Worker status_t status = sf->setTransactionState(FrameTimelineInfo{}, composerStates, displayStates,
1185*38e8c45fSAndroid Build Coastguard Worker ISurfaceComposer::eOneWay,
1186*38e8c45fSAndroid Build Coastguard Worker Transaction::getDefaultApplyToken(), {}, systemTime(),
1187*38e8c45fSAndroid Build Coastguard Worker true, {uncacheBuffer}, false, {}, generateId(), {});
1188*38e8c45fSAndroid Build Coastguard Worker if (status != NO_ERROR) {
1189*38e8c45fSAndroid Build Coastguard Worker ALOGE_AND_TRACE("SurfaceComposerClient::doUncacheBufferTransaction - %s",
1190*38e8c45fSAndroid Build Coastguard Worker strerror(-status));
1191*38e8c45fSAndroid Build Coastguard Worker }
1192*38e8c45fSAndroid Build Coastguard Worker }
1193*38e8c45fSAndroid Build Coastguard Worker
cacheBuffers()1194*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::cacheBuffers() {
1195*38e8c45fSAndroid Build Coastguard Worker if (!mMayContainBuffer) {
1196*38e8c45fSAndroid Build Coastguard Worker return;
1197*38e8c45fSAndroid Build Coastguard Worker }
1198*38e8c45fSAndroid Build Coastguard Worker
1199*38e8c45fSAndroid Build Coastguard Worker size_t count = 0;
1200*38e8c45fSAndroid Build Coastguard Worker for (auto& [handle, cs] : mComposerStates) {
1201*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = &(mComposerStates[handle].state);
1202*38e8c45fSAndroid Build Coastguard Worker if (!(s->what & layer_state_t::eBufferChanged)) {
1203*38e8c45fSAndroid Build Coastguard Worker continue;
1204*38e8c45fSAndroid Build Coastguard Worker } else if (s->bufferData &&
1205*38e8c45fSAndroid Build Coastguard Worker s->bufferData->flags.test(BufferData::BufferDataChange::cachedBufferChanged)) {
1206*38e8c45fSAndroid Build Coastguard Worker // If eBufferChanged and eCachedBufferChanged are both trued then that means
1207*38e8c45fSAndroid Build Coastguard Worker // we already cached the buffer in a previous call to cacheBuffers, perhaps
1208*38e8c45fSAndroid Build Coastguard Worker // from writeToParcel on a Transaction that was merged in to this one.
1209*38e8c45fSAndroid Build Coastguard Worker continue;
1210*38e8c45fSAndroid Build Coastguard Worker }
1211*38e8c45fSAndroid Build Coastguard Worker
1212*38e8c45fSAndroid Build Coastguard Worker // Don't try to cache a null buffer. Sending null buffers is cheap so we shouldn't waste
1213*38e8c45fSAndroid Build Coastguard Worker // time trying to cache them.
1214*38e8c45fSAndroid Build Coastguard Worker if (!s->bufferData || !s->bufferData->buffer) {
1215*38e8c45fSAndroid Build Coastguard Worker continue;
1216*38e8c45fSAndroid Build Coastguard Worker }
1217*38e8c45fSAndroid Build Coastguard Worker
1218*38e8c45fSAndroid Build Coastguard Worker uint64_t cacheId = 0;
1219*38e8c45fSAndroid Build Coastguard Worker status_t ret = BufferCache::getInstance().getCacheId(s->bufferData->buffer, &cacheId);
1220*38e8c45fSAndroid Build Coastguard Worker if (ret == NO_ERROR) {
1221*38e8c45fSAndroid Build Coastguard Worker // Cache-hit. Strip the buffer and send only the id.
1222*38e8c45fSAndroid Build Coastguard Worker s->bufferData->buffer = nullptr;
1223*38e8c45fSAndroid Build Coastguard Worker } else {
1224*38e8c45fSAndroid Build Coastguard Worker // Cache-miss. Include the buffer and send the new cacheId.
1225*38e8c45fSAndroid Build Coastguard Worker std::optional<client_cache_t> uncacheBuffer;
1226*38e8c45fSAndroid Build Coastguard Worker cacheId = BufferCache::getInstance().cache(s->bufferData->buffer, uncacheBuffer);
1227*38e8c45fSAndroid Build Coastguard Worker if (uncacheBuffer) {
1228*38e8c45fSAndroid Build Coastguard Worker mUncacheBuffers.push_back(*uncacheBuffer);
1229*38e8c45fSAndroid Build Coastguard Worker }
1230*38e8c45fSAndroid Build Coastguard Worker }
1231*38e8c45fSAndroid Build Coastguard Worker s->bufferData->flags |= BufferData::BufferDataChange::cachedBufferChanged;
1232*38e8c45fSAndroid Build Coastguard Worker s->bufferData->cachedBuffer.token = BufferCache::getInstance().getToken();
1233*38e8c45fSAndroid Build Coastguard Worker s->bufferData->cachedBuffer.id = cacheId;
1234*38e8c45fSAndroid Build Coastguard Worker
1235*38e8c45fSAndroid Build Coastguard Worker // If we have more buffers than the size of the cache, we should stop caching so we don't
1236*38e8c45fSAndroid Build Coastguard Worker // evict other buffers in this transaction
1237*38e8c45fSAndroid Build Coastguard Worker count++;
1238*38e8c45fSAndroid Build Coastguard Worker if (count >= BUFFER_CACHE_MAX_SIZE) {
1239*38e8c45fSAndroid Build Coastguard Worker break;
1240*38e8c45fSAndroid Build Coastguard Worker }
1241*38e8c45fSAndroid Build Coastguard Worker }
1242*38e8c45fSAndroid Build Coastguard Worker }
1243*38e8c45fSAndroid Build Coastguard Worker
1244*38e8c45fSAndroid Build Coastguard Worker class SyncCallback {
1245*38e8c45fSAndroid Build Coastguard Worker public:
getCallback(std::shared_ptr<SyncCallback> & callbackContext)1246*38e8c45fSAndroid Build Coastguard Worker static auto getCallback(std::shared_ptr<SyncCallback>& callbackContext) {
1247*38e8c45fSAndroid Build Coastguard Worker return [callbackContext](void* /* unused context */, nsecs_t /* latchTime */,
1248*38e8c45fSAndroid Build Coastguard Worker const sp<Fence>& /* presentFence */,
1249*38e8c45fSAndroid Build Coastguard Worker const std::vector<SurfaceControlStats>& /* stats */) {
1250*38e8c45fSAndroid Build Coastguard Worker if (!callbackContext) {
1251*38e8c45fSAndroid Build Coastguard Worker ALOGE("failed to get callback context for SyncCallback");
1252*38e8c45fSAndroid Build Coastguard Worker return;
1253*38e8c45fSAndroid Build Coastguard Worker }
1254*38e8c45fSAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(sem_post(&callbackContext->mSemaphore), "sem_post failed");
1255*38e8c45fSAndroid Build Coastguard Worker };
1256*38e8c45fSAndroid Build Coastguard Worker }
~SyncCallback()1257*38e8c45fSAndroid Build Coastguard Worker ~SyncCallback() {
1258*38e8c45fSAndroid Build Coastguard Worker if (mInitialized) {
1259*38e8c45fSAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(sem_destroy(&mSemaphore), "sem_destroy failed");
1260*38e8c45fSAndroid Build Coastguard Worker }
1261*38e8c45fSAndroid Build Coastguard Worker }
init()1262*38e8c45fSAndroid Build Coastguard Worker void init() {
1263*38e8c45fSAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(clock_gettime(CLOCK_MONOTONIC, &mTimeoutTimespec) == -1,
1264*38e8c45fSAndroid Build Coastguard Worker "clock_gettime() fail! in SyncCallback::init");
1265*38e8c45fSAndroid Build Coastguard Worker mTimeoutTimespec.tv_sec += 4;
1266*38e8c45fSAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(sem_init(&mSemaphore, 0, 0), "sem_init failed");
1267*38e8c45fSAndroid Build Coastguard Worker mInitialized = true;
1268*38e8c45fSAndroid Build Coastguard Worker }
wait()1269*38e8c45fSAndroid Build Coastguard Worker void wait() {
1270*38e8c45fSAndroid Build Coastguard Worker int result = sem_clockwait(&mSemaphore, CLOCK_MONOTONIC, &mTimeoutTimespec);
1271*38e8c45fSAndroid Build Coastguard Worker if (result && errno != ETIMEDOUT && errno != EINTR) {
1272*38e8c45fSAndroid Build Coastguard Worker LOG_ALWAYS_FATAL("sem_clockwait failed(%d)", errno);
1273*38e8c45fSAndroid Build Coastguard Worker } else if (errno == ETIMEDOUT) {
1274*38e8c45fSAndroid Build Coastguard Worker ALOGW("Sync transaction timed out waiting for commit callback.");
1275*38e8c45fSAndroid Build Coastguard Worker }
1276*38e8c45fSAndroid Build Coastguard Worker }
getContext()1277*38e8c45fSAndroid Build Coastguard Worker void* getContext() { return static_cast<void*>(this); }
1278*38e8c45fSAndroid Build Coastguard Worker
1279*38e8c45fSAndroid Build Coastguard Worker private:
1280*38e8c45fSAndroid Build Coastguard Worker sem_t mSemaphore;
1281*38e8c45fSAndroid Build Coastguard Worker bool mInitialized = false;
1282*38e8c45fSAndroid Build Coastguard Worker timespec mTimeoutTimespec;
1283*38e8c45fSAndroid Build Coastguard Worker };
1284*38e8c45fSAndroid Build Coastguard Worker
apply(bool synchronous,bool oneWay)1285*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay) {
1286*38e8c45fSAndroid Build Coastguard Worker if (mStatus != NO_ERROR) {
1287*38e8c45fSAndroid Build Coastguard Worker return mStatus;
1288*38e8c45fSAndroid Build Coastguard Worker }
1289*38e8c45fSAndroid Build Coastguard Worker
1290*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<SyncCallback> syncCallback = std::make_shared<SyncCallback>();
1291*38e8c45fSAndroid Build Coastguard Worker if (synchronous) {
1292*38e8c45fSAndroid Build Coastguard Worker syncCallback->init();
1293*38e8c45fSAndroid Build Coastguard Worker addTransactionCommittedCallback(SyncCallback::getCallback(syncCallback),
1294*38e8c45fSAndroid Build Coastguard Worker /*callbackContext=*/nullptr);
1295*38e8c45fSAndroid Build Coastguard Worker }
1296*38e8c45fSAndroid Build Coastguard Worker
1297*38e8c45fSAndroid Build Coastguard Worker bool hasListenerCallbacks = !mListenerCallbacks.empty();
1298*38e8c45fSAndroid Build Coastguard Worker std::vector<ListenerCallbacks> listenerCallbacks;
1299*38e8c45fSAndroid Build Coastguard Worker // For every listener with registered callbacks
1300*38e8c45fSAndroid Build Coastguard Worker for (const auto& [listener, callbackInfo] : mListenerCallbacks) {
1301*38e8c45fSAndroid Build Coastguard Worker auto& [callbackIds, surfaceControls] = callbackInfo;
1302*38e8c45fSAndroid Build Coastguard Worker if (callbackIds.empty()) {
1303*38e8c45fSAndroid Build Coastguard Worker continue;
1304*38e8c45fSAndroid Build Coastguard Worker }
1305*38e8c45fSAndroid Build Coastguard Worker
1306*38e8c45fSAndroid Build Coastguard Worker if (surfaceControls.empty()) {
1307*38e8c45fSAndroid Build Coastguard Worker listenerCallbacks.emplace_back(IInterface::asBinder(listener), std::move(callbackIds));
1308*38e8c45fSAndroid Build Coastguard Worker } else {
1309*38e8c45fSAndroid Build Coastguard Worker // If the listener has any SurfaceControls set on this Transaction update the surface
1310*38e8c45fSAndroid Build Coastguard Worker // state
1311*38e8c45fSAndroid Build Coastguard Worker for (const auto& surfaceControl : surfaceControls) {
1312*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(surfaceControl);
1313*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1314*38e8c45fSAndroid Build Coastguard Worker ALOGE("failed to get layer state");
1315*38e8c45fSAndroid Build Coastguard Worker continue;
1316*38e8c45fSAndroid Build Coastguard Worker }
1317*38e8c45fSAndroid Build Coastguard Worker std::vector<CallbackId> callbacks(callbackIds.begin(), callbackIds.end());
1318*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eHasListenerCallbacksChanged;
1319*38e8c45fSAndroid Build Coastguard Worker s->listeners.emplace_back(IInterface::asBinder(listener), callbacks);
1320*38e8c45fSAndroid Build Coastguard Worker }
1321*38e8c45fSAndroid Build Coastguard Worker }
1322*38e8c45fSAndroid Build Coastguard Worker }
1323*38e8c45fSAndroid Build Coastguard Worker
1324*38e8c45fSAndroid Build Coastguard Worker cacheBuffers();
1325*38e8c45fSAndroid Build Coastguard Worker
1326*38e8c45fSAndroid Build Coastguard Worker Vector<ComposerState> composerStates;
1327*38e8c45fSAndroid Build Coastguard Worker Vector<DisplayState> displayStates;
1328*38e8c45fSAndroid Build Coastguard Worker uint32_t flags = 0;
1329*38e8c45fSAndroid Build Coastguard Worker
1330*38e8c45fSAndroid Build Coastguard Worker for (auto const& kv : mComposerStates) {
1331*38e8c45fSAndroid Build Coastguard Worker composerStates.add(kv.second);
1332*38e8c45fSAndroid Build Coastguard Worker }
1333*38e8c45fSAndroid Build Coastguard Worker
1334*38e8c45fSAndroid Build Coastguard Worker displayStates = std::move(mDisplayStates);
1335*38e8c45fSAndroid Build Coastguard Worker
1336*38e8c45fSAndroid Build Coastguard Worker if (mAnimation) {
1337*38e8c45fSAndroid Build Coastguard Worker flags |= ISurfaceComposer::eAnimation;
1338*38e8c45fSAndroid Build Coastguard Worker }
1339*38e8c45fSAndroid Build Coastguard Worker if (oneWay) {
1340*38e8c45fSAndroid Build Coastguard Worker if (synchronous) {
1341*38e8c45fSAndroid Build Coastguard Worker ALOGE("Transaction attempted to set synchronous and one way at the same time"
1342*38e8c45fSAndroid Build Coastguard Worker " this is an invalid request. Synchronous will win for safety");
1343*38e8c45fSAndroid Build Coastguard Worker } else {
1344*38e8c45fSAndroid Build Coastguard Worker flags |= ISurfaceComposer::eOneWay;
1345*38e8c45fSAndroid Build Coastguard Worker }
1346*38e8c45fSAndroid Build Coastguard Worker }
1347*38e8c45fSAndroid Build Coastguard Worker
1348*38e8c45fSAndroid Build Coastguard Worker // If both mEarlyWakeupStart and mEarlyWakeupEnd are set
1349*38e8c45fSAndroid Build Coastguard Worker // it is equivalent for none
1350*38e8c45fSAndroid Build Coastguard Worker if (mEarlyWakeupStart && !mEarlyWakeupEnd) {
1351*38e8c45fSAndroid Build Coastguard Worker flags |= ISurfaceComposer::eEarlyWakeupStart;
1352*38e8c45fSAndroid Build Coastguard Worker }
1353*38e8c45fSAndroid Build Coastguard Worker if (mEarlyWakeupEnd && !mEarlyWakeupStart) {
1354*38e8c45fSAndroid Build Coastguard Worker flags |= ISurfaceComposer::eEarlyWakeupEnd;
1355*38e8c45fSAndroid Build Coastguard Worker }
1356*38e8c45fSAndroid Build Coastguard Worker
1357*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> applyToken = mApplyToken ? mApplyToken : getDefaultApplyToken();
1358*38e8c45fSAndroid Build Coastguard Worker
1359*38e8c45fSAndroid Build Coastguard Worker sp<ISurfaceComposer> sf(ComposerService::getComposerService());
1360*38e8c45fSAndroid Build Coastguard Worker status_t binderStatus =
1361*38e8c45fSAndroid Build Coastguard Worker sf->setTransactionState(mFrameTimelineInfo, composerStates, displayStates, flags,
1362*38e8c45fSAndroid Build Coastguard Worker applyToken, mInputWindowCommands, mDesiredPresentTime,
1363*38e8c45fSAndroid Build Coastguard Worker mIsAutoTimestamp, mUncacheBuffers, hasListenerCallbacks,
1364*38e8c45fSAndroid Build Coastguard Worker listenerCallbacks, mId, mMergedTransactionIds);
1365*38e8c45fSAndroid Build Coastguard Worker mId = generateId();
1366*38e8c45fSAndroid Build Coastguard Worker
1367*38e8c45fSAndroid Build Coastguard Worker // Clear the current states and flags
1368*38e8c45fSAndroid Build Coastguard Worker clear();
1369*38e8c45fSAndroid Build Coastguard Worker
1370*38e8c45fSAndroid Build Coastguard Worker if (synchronous && binderStatus == OK) {
1371*38e8c45fSAndroid Build Coastguard Worker syncCallback->wait();
1372*38e8c45fSAndroid Build Coastguard Worker }
1373*38e8c45fSAndroid Build Coastguard Worker
1374*38e8c45fSAndroid Build Coastguard Worker if (mLogCallPoints) {
1375*38e8c45fSAndroid Build Coastguard Worker ALOG(LOG_DEBUG, LOG_SURFACE_CONTROL_REGISTRY, "Transaction %" PRIu64 " applied", mId);
1376*38e8c45fSAndroid Build Coastguard Worker }
1377*38e8c45fSAndroid Build Coastguard Worker
1378*38e8c45fSAndroid Build Coastguard Worker mStatus = NO_ERROR;
1379*38e8c45fSAndroid Build Coastguard Worker return binderStatus;
1380*38e8c45fSAndroid Build Coastguard Worker }
1381*38e8c45fSAndroid Build Coastguard Worker
1382*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> SurfaceComposerClient::Transaction::sApplyToken = new BBinder();
1383*38e8c45fSAndroid Build Coastguard Worker
1384*38e8c45fSAndroid Build Coastguard Worker std::mutex SurfaceComposerClient::Transaction::sApplyTokenMutex;
1385*38e8c45fSAndroid Build Coastguard Worker
getDefaultApplyToken()1386*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> SurfaceComposerClient::Transaction::getDefaultApplyToken() {
1387*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock lock{sApplyTokenMutex};
1388*38e8c45fSAndroid Build Coastguard Worker return sApplyToken;
1389*38e8c45fSAndroid Build Coastguard Worker }
1390*38e8c45fSAndroid Build Coastguard Worker
setDefaultApplyToken(sp<IBinder> applyToken)1391*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::setDefaultApplyToken(sp<IBinder> applyToken) {
1392*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock lock{sApplyTokenMutex};
1393*38e8c45fSAndroid Build Coastguard Worker sApplyToken = std::move(applyToken);
1394*38e8c45fSAndroid Build Coastguard Worker }
1395*38e8c45fSAndroid Build Coastguard Worker
sendSurfaceFlushJankDataTransaction(const sp<SurfaceControl> & sc)1396*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::Transaction::sendSurfaceFlushJankDataTransaction(
1397*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc) {
1398*38e8c45fSAndroid Build Coastguard Worker Transaction t;
1399*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = t.getLayerState(sc);
1400*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1401*38e8c45fSAndroid Build Coastguard Worker return BAD_INDEX;
1402*38e8c45fSAndroid Build Coastguard Worker }
1403*38e8c45fSAndroid Build Coastguard Worker
1404*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eFlushJankData;
1405*38e8c45fSAndroid Build Coastguard Worker t.registerSurfaceControlForCallback(sc);
1406*38e8c45fSAndroid Build Coastguard Worker return t.apply(/*sync=*/false, /* oneWay=*/true);
1407*38e8c45fSAndroid Build Coastguard Worker }
1408*38e8c45fSAndroid Build Coastguard Worker
enableDebugLogCallPoints()1409*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::enableDebugLogCallPoints() {
1410*38e8c45fSAndroid Build Coastguard Worker mLogCallPoints = true;
1411*38e8c45fSAndroid Build Coastguard Worker }
1412*38e8c45fSAndroid Build Coastguard Worker
1413*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------
1414*38e8c45fSAndroid Build Coastguard Worker
createVirtualDisplay(const std::string & displayName,bool isSecure,const std::string & uniqueId,float requestedRefreshRate)1415*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> SurfaceComposerClient::createVirtualDisplay(const std::string& displayName,
1416*38e8c45fSAndroid Build Coastguard Worker bool isSecure, const std::string& uniqueId,
1417*38e8c45fSAndroid Build Coastguard Worker float requestedRefreshRate) {
1418*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> display = nullptr;
1419*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
1420*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->createVirtualDisplay(displayName, isSecure,
1421*38e8c45fSAndroid Build Coastguard Worker uniqueId,
1422*38e8c45fSAndroid Build Coastguard Worker requestedRefreshRate,
1423*38e8c45fSAndroid Build Coastguard Worker &display);
1424*38e8c45fSAndroid Build Coastguard Worker return status.isOk() ? display : nullptr;
1425*38e8c45fSAndroid Build Coastguard Worker }
1426*38e8c45fSAndroid Build Coastguard Worker
destroyVirtualDisplay(const sp<IBinder> & displayToken)1427*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::destroyVirtualDisplay(const sp<IBinder>& displayToken) {
1428*38e8c45fSAndroid Build Coastguard Worker return ComposerServiceAIDL::getComposerService()
1429*38e8c45fSAndroid Build Coastguard Worker ->destroyVirtualDisplay(displayToken)
1430*38e8c45fSAndroid Build Coastguard Worker .transactionError();
1431*38e8c45fSAndroid Build Coastguard Worker }
1432*38e8c45fSAndroid Build Coastguard Worker
getPhysicalDisplayIds()1433*38e8c45fSAndroid Build Coastguard Worker std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() {
1434*38e8c45fSAndroid Build Coastguard Worker std::vector<int64_t> displayIds;
1435*38e8c45fSAndroid Build Coastguard Worker std::vector<PhysicalDisplayId> physicalDisplayIds;
1436*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
1437*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getPhysicalDisplayIds(&displayIds);
1438*38e8c45fSAndroid Build Coastguard Worker if (status.isOk()) {
1439*38e8c45fSAndroid Build Coastguard Worker physicalDisplayIds.reserve(displayIds.size());
1440*38e8c45fSAndroid Build Coastguard Worker for (auto item : displayIds) {
1441*38e8c45fSAndroid Build Coastguard Worker auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(item));
1442*38e8c45fSAndroid Build Coastguard Worker physicalDisplayIds.push_back(*id);
1443*38e8c45fSAndroid Build Coastguard Worker }
1444*38e8c45fSAndroid Build Coastguard Worker }
1445*38e8c45fSAndroid Build Coastguard Worker return physicalDisplayIds;
1446*38e8c45fSAndroid Build Coastguard Worker }
1447*38e8c45fSAndroid Build Coastguard Worker
getPhysicalDisplayToken(PhysicalDisplayId displayId)1448*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId displayId) {
1449*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> display = nullptr;
1450*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
1451*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getPhysicalDisplayToken(displayId.value,
1452*38e8c45fSAndroid Build Coastguard Worker &display);
1453*38e8c45fSAndroid Build Coastguard Worker return status.isOk() ? display : nullptr;
1454*38e8c45fSAndroid Build Coastguard Worker }
1455*38e8c45fSAndroid Build Coastguard Worker
getStalledTransactionInfo(pid_t pid)1456*38e8c45fSAndroid Build Coastguard Worker std::optional<gui::StalledTransactionInfo> SurfaceComposerClient::getStalledTransactionInfo(
1457*38e8c45fSAndroid Build Coastguard Worker pid_t pid) {
1458*38e8c45fSAndroid Build Coastguard Worker std::optional<gui::StalledTransactionInfo> result;
1459*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getStalledTransactionInfo(pid, &result);
1460*38e8c45fSAndroid Build Coastguard Worker return result;
1461*38e8c45fSAndroid Build Coastguard Worker }
1462*38e8c45fSAndroid Build Coastguard Worker
setAnimationTransaction()1463*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::setAnimationTransaction() {
1464*38e8c45fSAndroid Build Coastguard Worker mAnimation = true;
1465*38e8c45fSAndroid Build Coastguard Worker }
1466*38e8c45fSAndroid Build Coastguard Worker
setEarlyWakeupStart()1467*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::setEarlyWakeupStart() {
1468*38e8c45fSAndroid Build Coastguard Worker mEarlyWakeupStart = true;
1469*38e8c45fSAndroid Build Coastguard Worker }
1470*38e8c45fSAndroid Build Coastguard Worker
setEarlyWakeupEnd()1471*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::setEarlyWakeupEnd() {
1472*38e8c45fSAndroid Build Coastguard Worker mEarlyWakeupEnd = true;
1473*38e8c45fSAndroid Build Coastguard Worker }
1474*38e8c45fSAndroid Build Coastguard Worker
getLayerState(const sp<SurfaceControl> & sc)1475*38e8c45fSAndroid Build Coastguard Worker layer_state_t* SurfaceComposerClient::Transaction::getLayerState(const sp<SurfaceControl>& sc) {
1476*38e8c45fSAndroid Build Coastguard Worker auto handle = sc->getLayerStateHandle();
1477*38e8c45fSAndroid Build Coastguard Worker
1478*38e8c45fSAndroid Build Coastguard Worker if (mComposerStates.count(handle) == 0) {
1479*38e8c45fSAndroid Build Coastguard Worker // we don't have it, add an initialized layer_state to our list
1480*38e8c45fSAndroid Build Coastguard Worker ComposerState s;
1481*38e8c45fSAndroid Build Coastguard Worker
1482*38e8c45fSAndroid Build Coastguard Worker s.state.surface = handle;
1483*38e8c45fSAndroid Build Coastguard Worker s.state.layerId = sc->getLayerId();
1484*38e8c45fSAndroid Build Coastguard Worker
1485*38e8c45fSAndroid Build Coastguard Worker mComposerStates[handle] = s;
1486*38e8c45fSAndroid Build Coastguard Worker }
1487*38e8c45fSAndroid Build Coastguard Worker
1488*38e8c45fSAndroid Build Coastguard Worker return &(mComposerStates[handle].state);
1489*38e8c45fSAndroid Build Coastguard Worker }
1490*38e8c45fSAndroid Build Coastguard Worker
registerSurfaceControlForCallback(const sp<SurfaceControl> & sc)1491*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::registerSurfaceControlForCallback(
1492*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc) {
1493*38e8c45fSAndroid Build Coastguard Worker auto& callbackInfo = mListenerCallbacks[TransactionCompletedListener::getIInstance()];
1494*38e8c45fSAndroid Build Coastguard Worker callbackInfo.surfaceControls.insert(sc);
1495*38e8c45fSAndroid Build Coastguard Worker
1496*38e8c45fSAndroid Build Coastguard Worker mTransactionCompletedListener->addSurfaceControlToCallbacks(sc, callbackInfo.callbackIds);
1497*38e8c45fSAndroid Build Coastguard Worker }
1498*38e8c45fSAndroid Build Coastguard Worker
setPosition(const sp<SurfaceControl> & sc,float x,float y)1499*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setPosition(
1500*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, float x, float y) {
1501*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1502*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1503*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1504*38e8c45fSAndroid Build Coastguard Worker return *this;
1505*38e8c45fSAndroid Build Coastguard Worker }
1506*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::ePositionChanged;
1507*38e8c45fSAndroid Build Coastguard Worker s->x = x;
1508*38e8c45fSAndroid Build Coastguard Worker s->y = y;
1509*38e8c45fSAndroid Build Coastguard Worker
1510*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1511*38e8c45fSAndroid Build Coastguard Worker return *this;
1512*38e8c45fSAndroid Build Coastguard Worker }
1513*38e8c45fSAndroid Build Coastguard Worker
show(const sp<SurfaceControl> & sc)1514*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::show(
1515*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc) {
1516*38e8c45fSAndroid Build Coastguard Worker return setFlags(sc, 0, layer_state_t::eLayerHidden);
1517*38e8c45fSAndroid Build Coastguard Worker }
1518*38e8c45fSAndroid Build Coastguard Worker
hide(const sp<SurfaceControl> & sc)1519*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::hide(
1520*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc) {
1521*38e8c45fSAndroid Build Coastguard Worker return setFlags(sc, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
1522*38e8c45fSAndroid Build Coastguard Worker }
1523*38e8c45fSAndroid Build Coastguard Worker
setLayer(const sp<SurfaceControl> & sc,int32_t z)1524*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayer(
1525*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, int32_t z) {
1526*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1527*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1528*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1529*38e8c45fSAndroid Build Coastguard Worker return *this;
1530*38e8c45fSAndroid Build Coastguard Worker }
1531*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eLayerChanged;
1532*38e8c45fSAndroid Build Coastguard Worker s->what &= ~layer_state_t::eRelativeLayerChanged;
1533*38e8c45fSAndroid Build Coastguard Worker s->z = z;
1534*38e8c45fSAndroid Build Coastguard Worker
1535*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1536*38e8c45fSAndroid Build Coastguard Worker return *this;
1537*38e8c45fSAndroid Build Coastguard Worker }
1538*38e8c45fSAndroid Build Coastguard Worker
setRelativeLayer(const sp<SurfaceControl> & sc,const sp<SurfaceControl> & relativeTo,int32_t z)1539*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelativeLayer(
1540*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const sp<SurfaceControl>& relativeTo, int32_t z) {
1541*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1542*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1543*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1544*38e8c45fSAndroid Build Coastguard Worker return *this;
1545*38e8c45fSAndroid Build Coastguard Worker }
1546*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eRelativeLayerChanged;
1547*38e8c45fSAndroid Build Coastguard Worker s->what &= ~layer_state_t::eLayerChanged;
1548*38e8c45fSAndroid Build Coastguard Worker s->relativeLayerSurfaceControl = relativeTo;
1549*38e8c45fSAndroid Build Coastguard Worker s->z = z;
1550*38e8c45fSAndroid Build Coastguard Worker
1551*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1552*38e8c45fSAndroid Build Coastguard Worker return *this;
1553*38e8c45fSAndroid Build Coastguard Worker }
1554*38e8c45fSAndroid Build Coastguard Worker
setFlags(const sp<SurfaceControl> & sc,uint32_t flags,uint32_t mask)1555*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFlags(
1556*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, uint32_t flags,
1557*38e8c45fSAndroid Build Coastguard Worker uint32_t mask) {
1558*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1559*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1560*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1561*38e8c45fSAndroid Build Coastguard Worker return *this;
1562*38e8c45fSAndroid Build Coastguard Worker }
1563*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eFlagsChanged;
1564*38e8c45fSAndroid Build Coastguard Worker s->flags &= ~mask;
1565*38e8c45fSAndroid Build Coastguard Worker s->flags |= (flags & mask);
1566*38e8c45fSAndroid Build Coastguard Worker s->mask |= mask;
1567*38e8c45fSAndroid Build Coastguard Worker
1568*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1569*38e8c45fSAndroid Build Coastguard Worker return *this;
1570*38e8c45fSAndroid Build Coastguard Worker }
1571*38e8c45fSAndroid Build Coastguard Worker
setTransparentRegionHint(const sp<SurfaceControl> & sc,const Region & transparentRegion)1572*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransparentRegionHint(
1573*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc,
1574*38e8c45fSAndroid Build Coastguard Worker const Region& transparentRegion) {
1575*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1576*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1577*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1578*38e8c45fSAndroid Build Coastguard Worker return *this;
1579*38e8c45fSAndroid Build Coastguard Worker }
1580*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eTransparentRegionChanged;
1581*38e8c45fSAndroid Build Coastguard Worker s->transparentRegion = transparentRegion;
1582*38e8c45fSAndroid Build Coastguard Worker
1583*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1584*38e8c45fSAndroid Build Coastguard Worker return *this;
1585*38e8c45fSAndroid Build Coastguard Worker }
1586*38e8c45fSAndroid Build Coastguard Worker
setDimmingEnabled(const sp<SurfaceControl> & sc,bool dimmingEnabled)1587*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDimmingEnabled(
1588*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, bool dimmingEnabled) {
1589*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1590*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1591*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1592*38e8c45fSAndroid Build Coastguard Worker return *this;
1593*38e8c45fSAndroid Build Coastguard Worker }
1594*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eDimmingEnabledChanged;
1595*38e8c45fSAndroid Build Coastguard Worker s->dimmingEnabled = dimmingEnabled;
1596*38e8c45fSAndroid Build Coastguard Worker
1597*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1598*38e8c45fSAndroid Build Coastguard Worker return *this;
1599*38e8c45fSAndroid Build Coastguard Worker }
1600*38e8c45fSAndroid Build Coastguard Worker
setAlpha(const sp<SurfaceControl> & sc,float alpha)1601*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAlpha(
1602*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, float alpha) {
1603*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1604*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1605*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1606*38e8c45fSAndroid Build Coastguard Worker return *this;
1607*38e8c45fSAndroid Build Coastguard Worker }
1608*38e8c45fSAndroid Build Coastguard Worker if (alpha < 0.0f || alpha > 1.0f) {
1609*38e8c45fSAndroid Build Coastguard Worker ALOGE("SurfaceComposerClient::Transaction::setAlpha: invalid alpha %f, clamping", alpha);
1610*38e8c45fSAndroid Build Coastguard Worker }
1611*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eAlphaChanged;
1612*38e8c45fSAndroid Build Coastguard Worker s->color.a = std::clamp(alpha, 0.f, 1.f);
1613*38e8c45fSAndroid Build Coastguard Worker
1614*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1615*38e8c45fSAndroid Build Coastguard Worker return *this;
1616*38e8c45fSAndroid Build Coastguard Worker }
1617*38e8c45fSAndroid Build Coastguard Worker
setLayerStack(const sp<SurfaceControl> & sc,ui::LayerStack layerStack)1618*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLayerStack(
1619*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, ui::LayerStack layerStack) {
1620*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1621*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1622*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1623*38e8c45fSAndroid Build Coastguard Worker return *this;
1624*38e8c45fSAndroid Build Coastguard Worker }
1625*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eLayerStackChanged;
1626*38e8c45fSAndroid Build Coastguard Worker s->layerStack = layerStack;
1627*38e8c45fSAndroid Build Coastguard Worker
1628*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1629*38e8c45fSAndroid Build Coastguard Worker return *this;
1630*38e8c45fSAndroid Build Coastguard Worker }
1631*38e8c45fSAndroid Build Coastguard Worker
setMetadata(const sp<SurfaceControl> & sc,uint32_t key,const Parcel & p)1632*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMetadata(
1633*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, uint32_t key, const Parcel& p) {
1634*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1635*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1636*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1637*38e8c45fSAndroid Build Coastguard Worker return *this;
1638*38e8c45fSAndroid Build Coastguard Worker }
1639*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eMetadataChanged;
1640*38e8c45fSAndroid Build Coastguard Worker
1641*38e8c45fSAndroid Build Coastguard Worker s->metadata.mMap[key] = {p.data(), p.data() + p.dataSize()};
1642*38e8c45fSAndroid Build Coastguard Worker
1643*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1644*38e8c45fSAndroid Build Coastguard Worker return *this;
1645*38e8c45fSAndroid Build Coastguard Worker }
1646*38e8c45fSAndroid Build Coastguard Worker
setMatrix(const sp<SurfaceControl> & sc,float dsdx,float dtdx,float dtdy,float dsdy)1647*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setMatrix(
1648*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, float dsdx, float dtdx,
1649*38e8c45fSAndroid Build Coastguard Worker float dtdy, float dsdy) {
1650*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1651*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1652*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1653*38e8c45fSAndroid Build Coastguard Worker return *this;
1654*38e8c45fSAndroid Build Coastguard Worker }
1655*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eMatrixChanged;
1656*38e8c45fSAndroid Build Coastguard Worker layer_state_t::matrix22_t matrix;
1657*38e8c45fSAndroid Build Coastguard Worker matrix.dsdx = dsdx;
1658*38e8c45fSAndroid Build Coastguard Worker matrix.dtdx = dtdx;
1659*38e8c45fSAndroid Build Coastguard Worker matrix.dsdy = dsdy;
1660*38e8c45fSAndroid Build Coastguard Worker matrix.dtdy = dtdy;
1661*38e8c45fSAndroid Build Coastguard Worker s->matrix = matrix;
1662*38e8c45fSAndroid Build Coastguard Worker
1663*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1664*38e8c45fSAndroid Build Coastguard Worker return *this;
1665*38e8c45fSAndroid Build Coastguard Worker }
1666*38e8c45fSAndroid Build Coastguard Worker
setCrop(const sp<SurfaceControl> & sc,const Rect & crop)1667*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop(
1668*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const Rect& crop) {
1669*38e8c45fSAndroid Build Coastguard Worker return setCrop(sc, crop.toFloatRect());
1670*38e8c45fSAndroid Build Coastguard Worker }
1671*38e8c45fSAndroid Build Coastguard Worker
setCrop(const sp<SurfaceControl> & sc,const FloatRect & crop)1672*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop(
1673*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const FloatRect& crop) {
1674*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1675*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1676*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1677*38e8c45fSAndroid Build Coastguard Worker return *this;
1678*38e8c45fSAndroid Build Coastguard Worker }
1679*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eCropChanged;
1680*38e8c45fSAndroid Build Coastguard Worker s->crop = crop;
1681*38e8c45fSAndroid Build Coastguard Worker
1682*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1683*38e8c45fSAndroid Build Coastguard Worker return *this;
1684*38e8c45fSAndroid Build Coastguard Worker }
1685*38e8c45fSAndroid Build Coastguard Worker
setCornerRadius(const sp<SurfaceControl> & sc,float cornerRadius)1686*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCornerRadius(
1687*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, float cornerRadius) {
1688*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1689*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1690*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1691*38e8c45fSAndroid Build Coastguard Worker return *this;
1692*38e8c45fSAndroid Build Coastguard Worker }
1693*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eCornerRadiusChanged;
1694*38e8c45fSAndroid Build Coastguard Worker s->cornerRadius = cornerRadius;
1695*38e8c45fSAndroid Build Coastguard Worker return *this;
1696*38e8c45fSAndroid Build Coastguard Worker }
1697*38e8c45fSAndroid Build Coastguard Worker
setBackgroundBlurRadius(const sp<SurfaceControl> & sc,int backgroundBlurRadius)1698*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundBlurRadius(
1699*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, int backgroundBlurRadius) {
1700*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1701*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1702*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1703*38e8c45fSAndroid Build Coastguard Worker return *this;
1704*38e8c45fSAndroid Build Coastguard Worker }
1705*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eBackgroundBlurRadiusChanged;
1706*38e8c45fSAndroid Build Coastguard Worker s->backgroundBlurRadius = backgroundBlurRadius;
1707*38e8c45fSAndroid Build Coastguard Worker return *this;
1708*38e8c45fSAndroid Build Coastguard Worker }
1709*38e8c45fSAndroid Build Coastguard Worker
setBlurRegions(const sp<SurfaceControl> & sc,const std::vector<BlurRegion> & blurRegions)1710*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBlurRegions(
1711*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const std::vector<BlurRegion>& blurRegions) {
1712*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1713*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1714*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1715*38e8c45fSAndroid Build Coastguard Worker return *this;
1716*38e8c45fSAndroid Build Coastguard Worker }
1717*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eBlurRegionsChanged;
1718*38e8c45fSAndroid Build Coastguard Worker s->blurRegions = blurRegions;
1719*38e8c45fSAndroid Build Coastguard Worker return *this;
1720*38e8c45fSAndroid Build Coastguard Worker }
1721*38e8c45fSAndroid Build Coastguard Worker
reparent(const sp<SurfaceControl> & sc,const sp<SurfaceControl> & newParent)1722*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent(
1723*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent) {
1724*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1725*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1726*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1727*38e8c45fSAndroid Build Coastguard Worker return *this;
1728*38e8c45fSAndroid Build Coastguard Worker }
1729*38e8c45fSAndroid Build Coastguard Worker if (SurfaceControl::isSameSurface(sc, newParent)) {
1730*38e8c45fSAndroid Build Coastguard Worker return *this;
1731*38e8c45fSAndroid Build Coastguard Worker }
1732*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eReparent;
1733*38e8c45fSAndroid Build Coastguard Worker s->parentSurfaceControlForChild = newParent ? newParent->getParentingLayer() : nullptr;
1734*38e8c45fSAndroid Build Coastguard Worker
1735*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1736*38e8c45fSAndroid Build Coastguard Worker return *this;
1737*38e8c45fSAndroid Build Coastguard Worker }
1738*38e8c45fSAndroid Build Coastguard Worker
setColor(const sp<SurfaceControl> & sc,const half3 & color)1739*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColor(
1740*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc,
1741*38e8c45fSAndroid Build Coastguard Worker const half3& color) {
1742*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1743*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1744*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1745*38e8c45fSAndroid Build Coastguard Worker return *this;
1746*38e8c45fSAndroid Build Coastguard Worker }
1747*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eColorChanged;
1748*38e8c45fSAndroid Build Coastguard Worker s->color.rgb = color;
1749*38e8c45fSAndroid Build Coastguard Worker
1750*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1751*38e8c45fSAndroid Build Coastguard Worker return *this;
1752*38e8c45fSAndroid Build Coastguard Worker }
1753*38e8c45fSAndroid Build Coastguard Worker
setBackgroundColor(const sp<SurfaceControl> & sc,const half3 & color,float alpha,ui::Dataspace dataspace)1754*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundColor(
1755*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const half3& color, float alpha, ui::Dataspace dataspace) {
1756*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1757*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1758*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1759*38e8c45fSAndroid Build Coastguard Worker return *this;
1760*38e8c45fSAndroid Build Coastguard Worker }
1761*38e8c45fSAndroid Build Coastguard Worker
1762*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eBackgroundColorChanged;
1763*38e8c45fSAndroid Build Coastguard Worker s->bgColor.rgb = color;
1764*38e8c45fSAndroid Build Coastguard Worker s->bgColor.a = alpha;
1765*38e8c45fSAndroid Build Coastguard Worker s->bgColorDataspace = dataspace;
1766*38e8c45fSAndroid Build Coastguard Worker
1767*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1768*38e8c45fSAndroid Build Coastguard Worker return *this;
1769*38e8c45fSAndroid Build Coastguard Worker }
1770*38e8c45fSAndroid Build Coastguard Worker
setTransform(const sp<SurfaceControl> & sc,uint32_t transform)1771*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTransform(
1772*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, uint32_t transform) {
1773*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1774*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1775*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1776*38e8c45fSAndroid Build Coastguard Worker return *this;
1777*38e8c45fSAndroid Build Coastguard Worker }
1778*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eBufferTransformChanged;
1779*38e8c45fSAndroid Build Coastguard Worker s->bufferTransform = transform;
1780*38e8c45fSAndroid Build Coastguard Worker
1781*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1782*38e8c45fSAndroid Build Coastguard Worker return *this;
1783*38e8c45fSAndroid Build Coastguard Worker }
1784*38e8c45fSAndroid Build Coastguard Worker
1785*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction&
setTransformToDisplayInverse(const sp<SurfaceControl> & sc,bool transformToDisplayInverse)1786*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction::setTransformToDisplayInverse(const sp<SurfaceControl>& sc,
1787*38e8c45fSAndroid Build Coastguard Worker bool transformToDisplayInverse) {
1788*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1789*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1790*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1791*38e8c45fSAndroid Build Coastguard Worker return *this;
1792*38e8c45fSAndroid Build Coastguard Worker }
1793*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eTransformToDisplayInverseChanged;
1794*38e8c45fSAndroid Build Coastguard Worker s->transformToDisplayInverse = transformToDisplayInverse;
1795*38e8c45fSAndroid Build Coastguard Worker
1796*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1797*38e8c45fSAndroid Build Coastguard Worker return *this;
1798*38e8c45fSAndroid Build Coastguard Worker }
1799*38e8c45fSAndroid Build Coastguard Worker
getAndClearBuffer(const sp<SurfaceControl> & sc)1800*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<BufferData> SurfaceComposerClient::Transaction::getAndClearBuffer(
1801*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc) {
1802*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1803*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1804*38e8c45fSAndroid Build Coastguard Worker return nullptr;
1805*38e8c45fSAndroid Build Coastguard Worker }
1806*38e8c45fSAndroid Build Coastguard Worker if (!(s->what & layer_state_t::eBufferChanged)) {
1807*38e8c45fSAndroid Build Coastguard Worker return nullptr;
1808*38e8c45fSAndroid Build Coastguard Worker }
1809*38e8c45fSAndroid Build Coastguard Worker
1810*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<BufferData> bufferData = std::move(s->bufferData);
1811*38e8c45fSAndroid Build Coastguard Worker
1812*38e8c45fSAndroid Build Coastguard Worker mTransactionCompletedListener->removeReleaseBufferCallback(
1813*38e8c45fSAndroid Build Coastguard Worker bufferData->generateReleaseCallbackId());
1814*38e8c45fSAndroid Build Coastguard Worker s->what &= ~layer_state_t::eBufferChanged;
1815*38e8c45fSAndroid Build Coastguard Worker s->bufferData = nullptr;
1816*38e8c45fSAndroid Build Coastguard Worker
1817*38e8c45fSAndroid Build Coastguard Worker return bufferData;
1818*38e8c45fSAndroid Build Coastguard Worker }
1819*38e8c45fSAndroid Build Coastguard Worker
setBufferHasBarrier(const sp<SurfaceControl> & sc,uint64_t barrierFrameNumber)1820*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBufferHasBarrier(
1821*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, uint64_t barrierFrameNumber) {
1822*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1823*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1824*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1825*38e8c45fSAndroid Build Coastguard Worker return *this;
1826*38e8c45fSAndroid Build Coastguard Worker }
1827*38e8c45fSAndroid Build Coastguard Worker s->bufferData->hasBarrier = true;
1828*38e8c45fSAndroid Build Coastguard Worker s->bufferData->barrierFrameNumber = barrierFrameNumber;
1829*38e8c45fSAndroid Build Coastguard Worker return *this;
1830*38e8c45fSAndroid Build Coastguard Worker }
1831*38e8c45fSAndroid Build Coastguard Worker
setBuffer(const sp<SurfaceControl> & sc,const sp<GraphicBuffer> & buffer,const std::optional<sp<Fence>> & fence,const std::optional<uint64_t> & optFrameNumber,uint32_t producerId,ReleaseBufferCallback callback,nsecs_t dequeueTime)1832*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffer(
1833*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer,
1834*38e8c45fSAndroid Build Coastguard Worker const std::optional<sp<Fence>>& fence, const std::optional<uint64_t>& optFrameNumber,
1835*38e8c45fSAndroid Build Coastguard Worker uint32_t producerId, ReleaseBufferCallback callback, nsecs_t dequeueTime) {
1836*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1837*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1838*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1839*38e8c45fSAndroid Build Coastguard Worker return *this;
1840*38e8c45fSAndroid Build Coastguard Worker }
1841*38e8c45fSAndroid Build Coastguard Worker
1842*38e8c45fSAndroid Build Coastguard Worker releaseBufferIfOverwriting(*s);
1843*38e8c45fSAndroid Build Coastguard Worker
1844*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<BufferData> bufferData = std::make_shared<BufferData>();
1845*38e8c45fSAndroid Build Coastguard Worker bufferData->buffer = buffer;
1846*38e8c45fSAndroid Build Coastguard Worker if (buffer) {
1847*38e8c45fSAndroid Build Coastguard Worker uint64_t frameNumber = sc->resolveFrameNumber(optFrameNumber);
1848*38e8c45fSAndroid Build Coastguard Worker bufferData->frameNumber = frameNumber;
1849*38e8c45fSAndroid Build Coastguard Worker bufferData->producerId = producerId;
1850*38e8c45fSAndroid Build Coastguard Worker bufferData->flags |= BufferData::BufferDataChange::frameNumberChanged;
1851*38e8c45fSAndroid Build Coastguard Worker bufferData->dequeueTime = dequeueTime;
1852*38e8c45fSAndroid Build Coastguard Worker if (fence) {
1853*38e8c45fSAndroid Build Coastguard Worker bufferData->acquireFence = *fence;
1854*38e8c45fSAndroid Build Coastguard Worker bufferData->flags |= BufferData::BufferDataChange::fenceChanged;
1855*38e8c45fSAndroid Build Coastguard Worker }
1856*38e8c45fSAndroid Build Coastguard Worker bufferData->releaseBufferEndpoint = IInterface::asBinder(mTransactionCompletedListener);
1857*38e8c45fSAndroid Build Coastguard Worker setReleaseBufferCallback(bufferData.get(), callback);
1858*38e8c45fSAndroid Build Coastguard Worker }
1859*38e8c45fSAndroid Build Coastguard Worker
1860*38e8c45fSAndroid Build Coastguard Worker if (mIsAutoTimestamp) {
1861*38e8c45fSAndroid Build Coastguard Worker mDesiredPresentTime = systemTime();
1862*38e8c45fSAndroid Build Coastguard Worker }
1863*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eBufferChanged;
1864*38e8c45fSAndroid Build Coastguard Worker s->bufferData = std::move(bufferData);
1865*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1866*38e8c45fSAndroid Build Coastguard Worker
1867*38e8c45fSAndroid Build Coastguard Worker // With the current infrastructure, a release callback will not be invoked if there's no
1868*38e8c45fSAndroid Build Coastguard Worker // transaction callback in the case when a buffer is latched and not released early. This is
1869*38e8c45fSAndroid Build Coastguard Worker // because the legacy implementation didn't have a release callback and sent releases in the
1870*38e8c45fSAndroid Build Coastguard Worker // transaction callback. Because of this, we need to make sure to have a transaction callback
1871*38e8c45fSAndroid Build Coastguard Worker // set up when a buffer is sent in a transaction to ensure the caller gets the release
1872*38e8c45fSAndroid Build Coastguard Worker // callback, regardless if they set up a transaction callback.
1873*38e8c45fSAndroid Build Coastguard Worker //
1874*38e8c45fSAndroid Build Coastguard Worker // TODO (b/230380821): Remove when release callbacks are separated from transaction callbacks
1875*38e8c45fSAndroid Build Coastguard Worker addTransactionCompletedCallback([](void*, nsecs_t, const sp<Fence>&,
1876*38e8c45fSAndroid Build Coastguard Worker const std::vector<SurfaceControlStats>&) {},
1877*38e8c45fSAndroid Build Coastguard Worker nullptr);
1878*38e8c45fSAndroid Build Coastguard Worker
1879*38e8c45fSAndroid Build Coastguard Worker mMayContainBuffer = true;
1880*38e8c45fSAndroid Build Coastguard Worker return *this;
1881*38e8c45fSAndroid Build Coastguard Worker }
1882*38e8c45fSAndroid Build Coastguard Worker
unsetBuffer(const sp<SurfaceControl> & sc)1883*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::unsetBuffer(
1884*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc) {
1885*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1886*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1887*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1888*38e8c45fSAndroid Build Coastguard Worker return *this;
1889*38e8c45fSAndroid Build Coastguard Worker }
1890*38e8c45fSAndroid Build Coastguard Worker
1891*38e8c45fSAndroid Build Coastguard Worker if (!(s->what & layer_state_t::eBufferChanged)) {
1892*38e8c45fSAndroid Build Coastguard Worker return *this;
1893*38e8c45fSAndroid Build Coastguard Worker }
1894*38e8c45fSAndroid Build Coastguard Worker
1895*38e8c45fSAndroid Build Coastguard Worker releaseBufferIfOverwriting(*s);
1896*38e8c45fSAndroid Build Coastguard Worker
1897*38e8c45fSAndroid Build Coastguard Worker s->what &= ~layer_state_t::eBufferChanged;
1898*38e8c45fSAndroid Build Coastguard Worker s->bufferData = nullptr;
1899*38e8c45fSAndroid Build Coastguard Worker return *this;
1900*38e8c45fSAndroid Build Coastguard Worker }
1901*38e8c45fSAndroid Build Coastguard Worker
setReleaseBufferCallback(BufferData * bufferData,ReleaseBufferCallback callback)1902*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::setReleaseBufferCallback(BufferData* bufferData,
1903*38e8c45fSAndroid Build Coastguard Worker ReleaseBufferCallback callback) {
1904*38e8c45fSAndroid Build Coastguard Worker if (!callback) {
1905*38e8c45fSAndroid Build Coastguard Worker return;
1906*38e8c45fSAndroid Build Coastguard Worker }
1907*38e8c45fSAndroid Build Coastguard Worker
1908*38e8c45fSAndroid Build Coastguard Worker if (!bufferData->buffer) {
1909*38e8c45fSAndroid Build Coastguard Worker ALOGW("Transaction::setReleaseBufferCallback"
1910*38e8c45fSAndroid Build Coastguard Worker "ignored trying to set a callback on a null buffer.");
1911*38e8c45fSAndroid Build Coastguard Worker return;
1912*38e8c45fSAndroid Build Coastguard Worker }
1913*38e8c45fSAndroid Build Coastguard Worker
1914*38e8c45fSAndroid Build Coastguard Worker bufferData->releaseBufferListener =
1915*38e8c45fSAndroid Build Coastguard Worker static_cast<sp<ITransactionCompletedListener>>(mTransactionCompletedListener);
1916*38e8c45fSAndroid Build Coastguard Worker mTransactionCompletedListener->setReleaseBufferCallback(bufferData->generateReleaseCallbackId(),
1917*38e8c45fSAndroid Build Coastguard Worker callback);
1918*38e8c45fSAndroid Build Coastguard Worker }
1919*38e8c45fSAndroid Build Coastguard Worker
setDataspace(const sp<SurfaceControl> & sc,ui::Dataspace dataspace)1920*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDataspace(
1921*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, ui::Dataspace dataspace) {
1922*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1923*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1924*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1925*38e8c45fSAndroid Build Coastguard Worker return *this;
1926*38e8c45fSAndroid Build Coastguard Worker }
1927*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eDataspaceChanged;
1928*38e8c45fSAndroid Build Coastguard Worker s->dataspace = dataspace;
1929*38e8c45fSAndroid Build Coastguard Worker
1930*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1931*38e8c45fSAndroid Build Coastguard Worker return *this;
1932*38e8c45fSAndroid Build Coastguard Worker }
1933*38e8c45fSAndroid Build Coastguard Worker
setExtendedRangeBrightness(const sp<SurfaceControl> & sc,float currentBufferRatio,float desiredRatio)1934*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setExtendedRangeBrightness(
1935*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, float currentBufferRatio, float desiredRatio) {
1936*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1937*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1938*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1939*38e8c45fSAndroid Build Coastguard Worker return *this;
1940*38e8c45fSAndroid Build Coastguard Worker }
1941*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eExtendedRangeBrightnessChanged;
1942*38e8c45fSAndroid Build Coastguard Worker s->currentHdrSdrRatio = currentBufferRatio;
1943*38e8c45fSAndroid Build Coastguard Worker s->desiredHdrSdrRatio = desiredRatio;
1944*38e8c45fSAndroid Build Coastguard Worker
1945*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1946*38e8c45fSAndroid Build Coastguard Worker return *this;
1947*38e8c45fSAndroid Build Coastguard Worker }
1948*38e8c45fSAndroid Build Coastguard Worker
setDesiredHdrHeadroom(const sp<SurfaceControl> & sc,float desiredRatio)1949*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDesiredHdrHeadroom(
1950*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, float desiredRatio) {
1951*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1952*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1953*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1954*38e8c45fSAndroid Build Coastguard Worker return *this;
1955*38e8c45fSAndroid Build Coastguard Worker }
1956*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eDesiredHdrHeadroomChanged;
1957*38e8c45fSAndroid Build Coastguard Worker s->desiredHdrSdrRatio = desiredRatio;
1958*38e8c45fSAndroid Build Coastguard Worker
1959*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1960*38e8c45fSAndroid Build Coastguard Worker return *this;
1961*38e8c45fSAndroid Build Coastguard Worker }
1962*38e8c45fSAndroid Build Coastguard Worker
setLuts(const sp<SurfaceControl> & sc,const base::unique_fd & lutFd,const std::vector<int32_t> & offsets,const std::vector<int32_t> & dimensions,const std::vector<int32_t> & sizes,const std::vector<int32_t> & samplingKeys)1963*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setLuts(
1964*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const base::unique_fd& lutFd,
1965*38e8c45fSAndroid Build Coastguard Worker const std::vector<int32_t>& offsets, const std::vector<int32_t>& dimensions,
1966*38e8c45fSAndroid Build Coastguard Worker const std::vector<int32_t>& sizes, const std::vector<int32_t>& samplingKeys) {
1967*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1968*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1969*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1970*38e8c45fSAndroid Build Coastguard Worker return *this;
1971*38e8c45fSAndroid Build Coastguard Worker }
1972*38e8c45fSAndroid Build Coastguard Worker
1973*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eLutsChanged;
1974*38e8c45fSAndroid Build Coastguard Worker if (lutFd.ok()) {
1975*38e8c45fSAndroid Build Coastguard Worker s->luts = std::make_shared<gui::DisplayLuts>(base::unique_fd(dup(lutFd.get())), offsets,
1976*38e8c45fSAndroid Build Coastguard Worker dimensions, sizes, samplingKeys);
1977*38e8c45fSAndroid Build Coastguard Worker } else {
1978*38e8c45fSAndroid Build Coastguard Worker s->luts = nullptr;
1979*38e8c45fSAndroid Build Coastguard Worker }
1980*38e8c45fSAndroid Build Coastguard Worker
1981*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1982*38e8c45fSAndroid Build Coastguard Worker return *this;
1983*38e8c45fSAndroid Build Coastguard Worker }
1984*38e8c45fSAndroid Build Coastguard Worker
setCachingHint(const sp<SurfaceControl> & sc,gui::CachingHint cachingHint)1985*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCachingHint(
1986*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, gui::CachingHint cachingHint) {
1987*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
1988*38e8c45fSAndroid Build Coastguard Worker if (!s) {
1989*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
1990*38e8c45fSAndroid Build Coastguard Worker return *this;
1991*38e8c45fSAndroid Build Coastguard Worker }
1992*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eCachingHintChanged;
1993*38e8c45fSAndroid Build Coastguard Worker s->cachingHint = cachingHint;
1994*38e8c45fSAndroid Build Coastguard Worker
1995*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
1996*38e8c45fSAndroid Build Coastguard Worker return *this;
1997*38e8c45fSAndroid Build Coastguard Worker }
1998*38e8c45fSAndroid Build Coastguard Worker
setHdrMetadata(const sp<SurfaceControl> & sc,const HdrMetadata & hdrMetadata)1999*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setHdrMetadata(
2000*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata) {
2001*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2002*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2003*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2004*38e8c45fSAndroid Build Coastguard Worker return *this;
2005*38e8c45fSAndroid Build Coastguard Worker }
2006*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eHdrMetadataChanged;
2007*38e8c45fSAndroid Build Coastguard Worker s->hdrMetadata = hdrMetadata;
2008*38e8c45fSAndroid Build Coastguard Worker
2009*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2010*38e8c45fSAndroid Build Coastguard Worker return *this;
2011*38e8c45fSAndroid Build Coastguard Worker }
2012*38e8c45fSAndroid Build Coastguard Worker
setSurfaceDamageRegion(const sp<SurfaceControl> & sc,const Region & surfaceDamageRegion)2013*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSurfaceDamageRegion(
2014*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const Region& surfaceDamageRegion) {
2015*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2016*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2017*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2018*38e8c45fSAndroid Build Coastguard Worker return *this;
2019*38e8c45fSAndroid Build Coastguard Worker }
2020*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eSurfaceDamageRegionChanged;
2021*38e8c45fSAndroid Build Coastguard Worker s->surfaceDamageRegion = surfaceDamageRegion;
2022*38e8c45fSAndroid Build Coastguard Worker
2023*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2024*38e8c45fSAndroid Build Coastguard Worker return *this;
2025*38e8c45fSAndroid Build Coastguard Worker }
2026*38e8c45fSAndroid Build Coastguard Worker
setApi(const sp<SurfaceControl> & sc,int32_t api)2027*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setApi(
2028*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, int32_t api) {
2029*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2030*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2031*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2032*38e8c45fSAndroid Build Coastguard Worker return *this;
2033*38e8c45fSAndroid Build Coastguard Worker }
2034*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eApiChanged;
2035*38e8c45fSAndroid Build Coastguard Worker s->api = api;
2036*38e8c45fSAndroid Build Coastguard Worker
2037*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2038*38e8c45fSAndroid Build Coastguard Worker return *this;
2039*38e8c45fSAndroid Build Coastguard Worker }
2040*38e8c45fSAndroid Build Coastguard Worker
setSidebandStream(const sp<SurfaceControl> & sc,const sp<NativeHandle> & sidebandStream)2041*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSidebandStream(
2042*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const sp<NativeHandle>& sidebandStream) {
2043*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2044*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2045*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2046*38e8c45fSAndroid Build Coastguard Worker return *this;
2047*38e8c45fSAndroid Build Coastguard Worker }
2048*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eSidebandStreamChanged;
2049*38e8c45fSAndroid Build Coastguard Worker s->sidebandStream = sidebandStream;
2050*38e8c45fSAndroid Build Coastguard Worker
2051*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2052*38e8c45fSAndroid Build Coastguard Worker return *this;
2053*38e8c45fSAndroid Build Coastguard Worker }
2054*38e8c45fSAndroid Build Coastguard Worker
setDesiredPresentTime(nsecs_t desiredPresentTime)2055*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDesiredPresentTime(
2056*38e8c45fSAndroid Build Coastguard Worker nsecs_t desiredPresentTime) {
2057*38e8c45fSAndroid Build Coastguard Worker mDesiredPresentTime = desiredPresentTime;
2058*38e8c45fSAndroid Build Coastguard Worker mIsAutoTimestamp = false;
2059*38e8c45fSAndroid Build Coastguard Worker return *this;
2060*38e8c45fSAndroid Build Coastguard Worker }
2061*38e8c45fSAndroid Build Coastguard Worker
setColorSpaceAgnostic(const sp<SurfaceControl> & sc,const bool agnostic)2062*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorSpaceAgnostic(
2063*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const bool agnostic) {
2064*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2065*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2066*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2067*38e8c45fSAndroid Build Coastguard Worker return *this;
2068*38e8c45fSAndroid Build Coastguard Worker }
2069*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eColorSpaceAgnosticChanged;
2070*38e8c45fSAndroid Build Coastguard Worker s->colorSpaceAgnostic = agnostic;
2071*38e8c45fSAndroid Build Coastguard Worker
2072*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2073*38e8c45fSAndroid Build Coastguard Worker return *this;
2074*38e8c45fSAndroid Build Coastguard Worker }
2075*38e8c45fSAndroid Build Coastguard Worker
2076*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction&
setFrameRateSelectionPriority(const sp<SurfaceControl> & sc,int32_t priority)2077*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction::setFrameRateSelectionPriority(const sp<SurfaceControl>& sc,
2078*38e8c45fSAndroid Build Coastguard Worker int32_t priority) {
2079*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2080*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2081*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2082*38e8c45fSAndroid Build Coastguard Worker return *this;
2083*38e8c45fSAndroid Build Coastguard Worker }
2084*38e8c45fSAndroid Build Coastguard Worker
2085*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eFrameRateSelectionPriority;
2086*38e8c45fSAndroid Build Coastguard Worker s->frameRateSelectionPriority = priority;
2087*38e8c45fSAndroid Build Coastguard Worker
2088*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2089*38e8c45fSAndroid Build Coastguard Worker return *this;
2090*38e8c45fSAndroid Build Coastguard Worker }
2091*38e8c45fSAndroid Build Coastguard Worker
addTransactionCallback(TransactionCompletedCallbackTakesContext callback,void * callbackContext,CallbackId::Type callbackType)2092*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::addTransactionCallback(
2093*38e8c45fSAndroid Build Coastguard Worker TransactionCompletedCallbackTakesContext callback, void* callbackContext,
2094*38e8c45fSAndroid Build Coastguard Worker CallbackId::Type callbackType) {
2095*38e8c45fSAndroid Build Coastguard Worker auto callbackWithContext =
2096*38e8c45fSAndroid Build Coastguard Worker std::bind(std::move(callback), callbackContext, std::placeholders::_1,
2097*38e8c45fSAndroid Build Coastguard Worker std::placeholders::_2, std::placeholders::_3);
2098*38e8c45fSAndroid Build Coastguard Worker const auto& surfaceControls = mListenerCallbacks[mTransactionCompletedListener].surfaceControls;
2099*38e8c45fSAndroid Build Coastguard Worker
2100*38e8c45fSAndroid Build Coastguard Worker CallbackId callbackId =
2101*38e8c45fSAndroid Build Coastguard Worker mTransactionCompletedListener->addCallbackFunction(callbackWithContext, surfaceControls,
2102*38e8c45fSAndroid Build Coastguard Worker callbackType);
2103*38e8c45fSAndroid Build Coastguard Worker
2104*38e8c45fSAndroid Build Coastguard Worker mListenerCallbacks[mTransactionCompletedListener].callbackIds.emplace(callbackId);
2105*38e8c45fSAndroid Build Coastguard Worker return *this;
2106*38e8c45fSAndroid Build Coastguard Worker }
2107*38e8c45fSAndroid Build Coastguard Worker
2108*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction&
addTransactionCompletedCallback(TransactionCompletedCallbackTakesContext callback,void * callbackContext)2109*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction::addTransactionCompletedCallback(
2110*38e8c45fSAndroid Build Coastguard Worker TransactionCompletedCallbackTakesContext callback, void* callbackContext) {
2111*38e8c45fSAndroid Build Coastguard Worker return addTransactionCallback(std::move(callback), callbackContext,
2112*38e8c45fSAndroid Build Coastguard Worker CallbackId::Type::ON_COMPLETE);
2113*38e8c45fSAndroid Build Coastguard Worker }
2114*38e8c45fSAndroid Build Coastguard Worker
2115*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction&
addTransactionCommittedCallback(TransactionCompletedCallbackTakesContext callback,void * callbackContext)2116*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction::addTransactionCommittedCallback(
2117*38e8c45fSAndroid Build Coastguard Worker TransactionCompletedCallbackTakesContext callback, void* callbackContext) {
2118*38e8c45fSAndroid Build Coastguard Worker return addTransactionCallback(std::move(callback), callbackContext,
2119*38e8c45fSAndroid Build Coastguard Worker CallbackId::Type::ON_COMMIT);
2120*38e8c45fSAndroid Build Coastguard Worker }
2121*38e8c45fSAndroid Build Coastguard Worker
notifyProducerDisconnect(const sp<SurfaceControl> & sc)2122*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::notifyProducerDisconnect(
2123*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc) {
2124*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2125*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2126*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2127*38e8c45fSAndroid Build Coastguard Worker return *this;
2128*38e8c45fSAndroid Build Coastguard Worker }
2129*38e8c45fSAndroid Build Coastguard Worker
2130*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eProducerDisconnect;
2131*38e8c45fSAndroid Build Coastguard Worker return *this;
2132*38e8c45fSAndroid Build Coastguard Worker }
2133*38e8c45fSAndroid Build Coastguard Worker
setInputWindowInfo(const sp<SurfaceControl> & sc,sp<WindowInfoHandle> info)2134*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setInputWindowInfo(
2135*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, sp<WindowInfoHandle> info) {
2136*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2137*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2138*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2139*38e8c45fSAndroid Build Coastguard Worker return *this;
2140*38e8c45fSAndroid Build Coastguard Worker }
2141*38e8c45fSAndroid Build Coastguard Worker s->windowInfoHandle = std::move(info);
2142*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eInputInfoChanged;
2143*38e8c45fSAndroid Build Coastguard Worker return *this;
2144*38e8c45fSAndroid Build Coastguard Worker }
2145*38e8c45fSAndroid Build Coastguard Worker
setFocusedWindow(const FocusRequest & request)2146*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFocusedWindow(
2147*38e8c45fSAndroid Build Coastguard Worker const FocusRequest& request) {
2148*38e8c45fSAndroid Build Coastguard Worker mInputWindowCommands.focusRequests.push_back(request);
2149*38e8c45fSAndroid Build Coastguard Worker return *this;
2150*38e8c45fSAndroid Build Coastguard Worker }
2151*38e8c45fSAndroid Build Coastguard Worker
2152*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction&
addWindowInfosReportedListener(sp<gui::IWindowInfosReportedListener> windowInfosReportedListener)2153*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction::addWindowInfosReportedListener(
2154*38e8c45fSAndroid Build Coastguard Worker sp<gui::IWindowInfosReportedListener> windowInfosReportedListener) {
2155*38e8c45fSAndroid Build Coastguard Worker mInputWindowCommands.windowInfosReportedListeners.insert(windowInfosReportedListener);
2156*38e8c45fSAndroid Build Coastguard Worker return *this;
2157*38e8c45fSAndroid Build Coastguard Worker }
2158*38e8c45fSAndroid Build Coastguard Worker
setColorTransform(const sp<SurfaceControl> & sc,const mat3 & matrix,const vec3 & translation)2159*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setColorTransform(
2160*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const mat3& matrix, const vec3& translation) {
2161*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2162*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2163*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2164*38e8c45fSAndroid Build Coastguard Worker return *this;
2165*38e8c45fSAndroid Build Coastguard Worker }
2166*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eColorTransformChanged;
2167*38e8c45fSAndroid Build Coastguard Worker s->colorTransform = mat4(matrix, translation);
2168*38e8c45fSAndroid Build Coastguard Worker
2169*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2170*38e8c45fSAndroid Build Coastguard Worker return *this;
2171*38e8c45fSAndroid Build Coastguard Worker }
2172*38e8c45fSAndroid Build Coastguard Worker
setGeometry(const sp<SurfaceControl> & sc,const Rect & source,const Rect & dst,int transform)2173*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setGeometry(
2174*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const Rect& source, const Rect& dst, int transform) {
2175*38e8c45fSAndroid Build Coastguard Worker setCrop(sc, source);
2176*38e8c45fSAndroid Build Coastguard Worker
2177*38e8c45fSAndroid Build Coastguard Worker int x = dst.left;
2178*38e8c45fSAndroid Build Coastguard Worker int y = dst.top;
2179*38e8c45fSAndroid Build Coastguard Worker
2180*38e8c45fSAndroid Build Coastguard Worker float sourceWidth = source.getWidth();
2181*38e8c45fSAndroid Build Coastguard Worker float sourceHeight = source.getHeight();
2182*38e8c45fSAndroid Build Coastguard Worker
2183*38e8c45fSAndroid Build Coastguard Worker float xScale = sourceWidth < 0 ? 1.0f : dst.getWidth() / sourceWidth;
2184*38e8c45fSAndroid Build Coastguard Worker float yScale = sourceHeight < 0 ? 1.0f : dst.getHeight() / sourceHeight;
2185*38e8c45fSAndroid Build Coastguard Worker float matrix[4] = {1, 0, 0, 1};
2186*38e8c45fSAndroid Build Coastguard Worker
2187*38e8c45fSAndroid Build Coastguard Worker switch (transform) {
2188*38e8c45fSAndroid Build Coastguard Worker case NATIVE_WINDOW_TRANSFORM_FLIP_H:
2189*38e8c45fSAndroid Build Coastguard Worker matrix[0] = -xScale; matrix[1] = 0;
2190*38e8c45fSAndroid Build Coastguard Worker matrix[2] = 0; matrix[3] = yScale;
2191*38e8c45fSAndroid Build Coastguard Worker x += source.getWidth();
2192*38e8c45fSAndroid Build Coastguard Worker break;
2193*38e8c45fSAndroid Build Coastguard Worker case NATIVE_WINDOW_TRANSFORM_FLIP_V:
2194*38e8c45fSAndroid Build Coastguard Worker matrix[0] = xScale; matrix[1] = 0;
2195*38e8c45fSAndroid Build Coastguard Worker matrix[2] = 0; matrix[3] = -yScale;
2196*38e8c45fSAndroid Build Coastguard Worker y += source.getHeight();
2197*38e8c45fSAndroid Build Coastguard Worker break;
2198*38e8c45fSAndroid Build Coastguard Worker case NATIVE_WINDOW_TRANSFORM_ROT_90:
2199*38e8c45fSAndroid Build Coastguard Worker matrix[0] = 0; matrix[1] = -yScale;
2200*38e8c45fSAndroid Build Coastguard Worker matrix[2] = xScale; matrix[3] = 0;
2201*38e8c45fSAndroid Build Coastguard Worker x += source.getHeight();
2202*38e8c45fSAndroid Build Coastguard Worker break;
2203*38e8c45fSAndroid Build Coastguard Worker case NATIVE_WINDOW_TRANSFORM_ROT_180:
2204*38e8c45fSAndroid Build Coastguard Worker matrix[0] = -xScale; matrix[1] = 0;
2205*38e8c45fSAndroid Build Coastguard Worker matrix[2] = 0; matrix[3] = -yScale;
2206*38e8c45fSAndroid Build Coastguard Worker x += source.getWidth();
2207*38e8c45fSAndroid Build Coastguard Worker y += source.getHeight();
2208*38e8c45fSAndroid Build Coastguard Worker break;
2209*38e8c45fSAndroid Build Coastguard Worker case NATIVE_WINDOW_TRANSFORM_ROT_270:
2210*38e8c45fSAndroid Build Coastguard Worker matrix[0] = 0; matrix[1] = yScale;
2211*38e8c45fSAndroid Build Coastguard Worker matrix[2] = -xScale; matrix[3] = 0;
2212*38e8c45fSAndroid Build Coastguard Worker y += source.getWidth();
2213*38e8c45fSAndroid Build Coastguard Worker break;
2214*38e8c45fSAndroid Build Coastguard Worker default:
2215*38e8c45fSAndroid Build Coastguard Worker matrix[0] = xScale; matrix[1] = 0;
2216*38e8c45fSAndroid Build Coastguard Worker matrix[2] = 0; matrix[3] = yScale;
2217*38e8c45fSAndroid Build Coastguard Worker break;
2218*38e8c45fSAndroid Build Coastguard Worker }
2219*38e8c45fSAndroid Build Coastguard Worker setMatrix(sc, matrix[0], matrix[1], matrix[2], matrix[3]);
2220*38e8c45fSAndroid Build Coastguard Worker float offsetX = xScale * source.left;
2221*38e8c45fSAndroid Build Coastguard Worker float offsetY = yScale * source.top;
2222*38e8c45fSAndroid Build Coastguard Worker setPosition(sc, x - offsetX, y - offsetY);
2223*38e8c45fSAndroid Build Coastguard Worker
2224*38e8c45fSAndroid Build Coastguard Worker return *this;
2225*38e8c45fSAndroid Build Coastguard Worker }
2226*38e8c45fSAndroid Build Coastguard Worker
setShadowRadius(const sp<SurfaceControl> & sc,float shadowRadius)2227*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setShadowRadius(
2228*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, float shadowRadius) {
2229*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2230*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2231*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2232*38e8c45fSAndroid Build Coastguard Worker return *this;
2233*38e8c45fSAndroid Build Coastguard Worker }
2234*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eShadowRadiusChanged;
2235*38e8c45fSAndroid Build Coastguard Worker s->shadowRadius = shadowRadius;
2236*38e8c45fSAndroid Build Coastguard Worker return *this;
2237*38e8c45fSAndroid Build Coastguard Worker }
2238*38e8c45fSAndroid Build Coastguard Worker
setFrameRate(const sp<SurfaceControl> & sc,float frameRate,int8_t compatibility,int8_t changeFrameRateStrategy)2239*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameRate(
2240*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, float frameRate, int8_t compatibility,
2241*38e8c45fSAndroid Build Coastguard Worker int8_t changeFrameRateStrategy) {
2242*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2243*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2244*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2245*38e8c45fSAndroid Build Coastguard Worker return *this;
2246*38e8c45fSAndroid Build Coastguard Worker }
2247*38e8c45fSAndroid Build Coastguard Worker // Allow privileged values as well here, those will be ignored by SF if
2248*38e8c45fSAndroid Build Coastguard Worker // the caller is not privileged
2249*38e8c45fSAndroid Build Coastguard Worker if (!ValidateFrameRate(frameRate, compatibility, changeFrameRateStrategy,
2250*38e8c45fSAndroid Build Coastguard Worker "Transaction::setFrameRate",
2251*38e8c45fSAndroid Build Coastguard Worker /*privileged=*/true)) {
2252*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_VALUE;
2253*38e8c45fSAndroid Build Coastguard Worker return *this;
2254*38e8c45fSAndroid Build Coastguard Worker }
2255*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eFrameRateChanged;
2256*38e8c45fSAndroid Build Coastguard Worker s->frameRate = frameRate;
2257*38e8c45fSAndroid Build Coastguard Worker s->frameRateCompatibility = compatibility;
2258*38e8c45fSAndroid Build Coastguard Worker s->changeFrameRateStrategy = changeFrameRateStrategy;
2259*38e8c45fSAndroid Build Coastguard Worker return *this;
2260*38e8c45fSAndroid Build Coastguard Worker }
2261*38e8c45fSAndroid Build Coastguard Worker
2262*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction&
setDefaultFrameRateCompatibility(const sp<SurfaceControl> & sc,int8_t compatibility)2263*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction::setDefaultFrameRateCompatibility(const sp<SurfaceControl>& sc,
2264*38e8c45fSAndroid Build Coastguard Worker int8_t compatibility) {
2265*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2266*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2267*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2268*38e8c45fSAndroid Build Coastguard Worker return *this;
2269*38e8c45fSAndroid Build Coastguard Worker }
2270*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eDefaultFrameRateCompatibilityChanged;
2271*38e8c45fSAndroid Build Coastguard Worker s->defaultFrameRateCompatibility = compatibility;
2272*38e8c45fSAndroid Build Coastguard Worker return *this;
2273*38e8c45fSAndroid Build Coastguard Worker }
2274*38e8c45fSAndroid Build Coastguard Worker
setFrameRateCategory(const sp<SurfaceControl> & sc,int8_t category,bool smoothSwitchOnly)2275*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameRateCategory(
2276*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, int8_t category, bool smoothSwitchOnly) {
2277*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2278*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2279*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2280*38e8c45fSAndroid Build Coastguard Worker return *this;
2281*38e8c45fSAndroid Build Coastguard Worker }
2282*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eFrameRateCategoryChanged;
2283*38e8c45fSAndroid Build Coastguard Worker s->frameRateCategory = category;
2284*38e8c45fSAndroid Build Coastguard Worker s->frameRateCategorySmoothSwitchOnly = smoothSwitchOnly;
2285*38e8c45fSAndroid Build Coastguard Worker return *this;
2286*38e8c45fSAndroid Build Coastguard Worker }
2287*38e8c45fSAndroid Build Coastguard Worker
2288*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction&
setFrameRateSelectionStrategy(const sp<SurfaceControl> & sc,int8_t strategy)2289*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction::setFrameRateSelectionStrategy(const sp<SurfaceControl>& sc,
2290*38e8c45fSAndroid Build Coastguard Worker int8_t strategy) {
2291*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2292*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2293*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2294*38e8c45fSAndroid Build Coastguard Worker return *this;
2295*38e8c45fSAndroid Build Coastguard Worker }
2296*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eFrameRateSelectionStrategyChanged;
2297*38e8c45fSAndroid Build Coastguard Worker s->frameRateSelectionStrategy = strategy;
2298*38e8c45fSAndroid Build Coastguard Worker return *this;
2299*38e8c45fSAndroid Build Coastguard Worker }
2300*38e8c45fSAndroid Build Coastguard Worker
setFixedTransformHint(const sp<SurfaceControl> & sc,int32_t fixedTransformHint)2301*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFixedTransformHint(
2302*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, int32_t fixedTransformHint) {
2303*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2304*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2305*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2306*38e8c45fSAndroid Build Coastguard Worker return *this;
2307*38e8c45fSAndroid Build Coastguard Worker }
2308*38e8c45fSAndroid Build Coastguard Worker
2309*38e8c45fSAndroid Build Coastguard Worker const ui::Transform::RotationFlags transform = fixedTransformHint == -1
2310*38e8c45fSAndroid Build Coastguard Worker ? ui::Transform::ROT_INVALID
2311*38e8c45fSAndroid Build Coastguard Worker : ui::Transform::toRotationFlags(static_cast<ui::Rotation>(fixedTransformHint));
2312*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eFixedTransformHintChanged;
2313*38e8c45fSAndroid Build Coastguard Worker s->fixedTransformHint = transform;
2314*38e8c45fSAndroid Build Coastguard Worker return *this;
2315*38e8c45fSAndroid Build Coastguard Worker }
2316*38e8c45fSAndroid Build Coastguard Worker
setFrameTimelineInfo(const FrameTimelineInfo & frameTimelineInfo)2317*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameTimelineInfo(
2318*38e8c45fSAndroid Build Coastguard Worker const FrameTimelineInfo& frameTimelineInfo) {
2319*38e8c45fSAndroid Build Coastguard Worker mergeFrameTimelineInfo(mFrameTimelineInfo, frameTimelineInfo);
2320*38e8c45fSAndroid Build Coastguard Worker return *this;
2321*38e8c45fSAndroid Build Coastguard Worker }
2322*38e8c45fSAndroid Build Coastguard Worker
setAutoRefresh(const sp<SurfaceControl> & sc,bool autoRefresh)2323*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAutoRefresh(
2324*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, bool autoRefresh) {
2325*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2326*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2327*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2328*38e8c45fSAndroid Build Coastguard Worker return *this;
2329*38e8c45fSAndroid Build Coastguard Worker }
2330*38e8c45fSAndroid Build Coastguard Worker
2331*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eAutoRefreshChanged;
2332*38e8c45fSAndroid Build Coastguard Worker s->autoRefresh = autoRefresh;
2333*38e8c45fSAndroid Build Coastguard Worker return *this;
2334*38e8c45fSAndroid Build Coastguard Worker }
2335*38e8c45fSAndroid Build Coastguard Worker
setTrustedOverlay(const sp<SurfaceControl> & sc,bool isTrustedOverlay)2336*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTrustedOverlay(
2337*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, bool isTrustedOverlay) {
2338*38e8c45fSAndroid Build Coastguard Worker return setTrustedOverlay(sc,
2339*38e8c45fSAndroid Build Coastguard Worker isTrustedOverlay ? gui::TrustedOverlay::ENABLED
2340*38e8c45fSAndroid Build Coastguard Worker : gui::TrustedOverlay::UNSET);
2341*38e8c45fSAndroid Build Coastguard Worker }
2342*38e8c45fSAndroid Build Coastguard Worker
setTrustedOverlay(const sp<SurfaceControl> & sc,gui::TrustedOverlay trustedOverlay)2343*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTrustedOverlay(
2344*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, gui::TrustedOverlay trustedOverlay) {
2345*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2346*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2347*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2348*38e8c45fSAndroid Build Coastguard Worker return *this;
2349*38e8c45fSAndroid Build Coastguard Worker }
2350*38e8c45fSAndroid Build Coastguard Worker
2351*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eTrustedOverlayChanged;
2352*38e8c45fSAndroid Build Coastguard Worker s->trustedOverlay = trustedOverlay;
2353*38e8c45fSAndroid Build Coastguard Worker return *this;
2354*38e8c45fSAndroid Build Coastguard Worker }
2355*38e8c45fSAndroid Build Coastguard Worker
setApplyToken(const sp<IBinder> & applyToken)2356*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setApplyToken(
2357*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& applyToken) {
2358*38e8c45fSAndroid Build Coastguard Worker mApplyToken = applyToken;
2359*38e8c45fSAndroid Build Coastguard Worker return *this;
2360*38e8c45fSAndroid Build Coastguard Worker }
2361*38e8c45fSAndroid Build Coastguard Worker
setStretchEffect(const sp<SurfaceControl> & sc,const StretchEffect & stretchEffect)2362*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setStretchEffect(
2363*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const StretchEffect& stretchEffect) {
2364*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2365*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2366*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2367*38e8c45fSAndroid Build Coastguard Worker return *this;
2368*38e8c45fSAndroid Build Coastguard Worker }
2369*38e8c45fSAndroid Build Coastguard Worker
2370*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eStretchChanged;
2371*38e8c45fSAndroid Build Coastguard Worker s->stretchEffect = stretchEffect;
2372*38e8c45fSAndroid Build Coastguard Worker return *this;
2373*38e8c45fSAndroid Build Coastguard Worker }
2374*38e8c45fSAndroid Build Coastguard Worker
flagEdgeExtensionEffectUseShader()2375*38e8c45fSAndroid Build Coastguard Worker bool SurfaceComposerClient::flagEdgeExtensionEffectUseShader() {
2376*38e8c45fSAndroid Build Coastguard Worker return com::android::graphics::libgui::flags::edge_extension_shader();
2377*38e8c45fSAndroid Build Coastguard Worker }
2378*38e8c45fSAndroid Build Coastguard Worker
setEdgeExtensionEffect(const sp<SurfaceControl> & sc,const gui::EdgeExtensionParameters & effect)2379*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setEdgeExtensionEffect(
2380*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const gui::EdgeExtensionParameters& effect) {
2381*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2382*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2383*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2384*38e8c45fSAndroid Build Coastguard Worker return *this;
2385*38e8c45fSAndroid Build Coastguard Worker }
2386*38e8c45fSAndroid Build Coastguard Worker
2387*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eEdgeExtensionChanged;
2388*38e8c45fSAndroid Build Coastguard Worker s->edgeExtensionParameters = effect;
2389*38e8c45fSAndroid Build Coastguard Worker return *this;
2390*38e8c45fSAndroid Build Coastguard Worker }
2391*38e8c45fSAndroid Build Coastguard Worker
setBufferCrop(const sp<SurfaceControl> & sc,const Rect & bufferCrop)2392*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBufferCrop(
2393*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const Rect& bufferCrop) {
2394*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2395*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2396*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2397*38e8c45fSAndroid Build Coastguard Worker return *this;
2398*38e8c45fSAndroid Build Coastguard Worker }
2399*38e8c45fSAndroid Build Coastguard Worker
2400*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eBufferCropChanged;
2401*38e8c45fSAndroid Build Coastguard Worker s->bufferCrop = bufferCrop;
2402*38e8c45fSAndroid Build Coastguard Worker
2403*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2404*38e8c45fSAndroid Build Coastguard Worker return *this;
2405*38e8c45fSAndroid Build Coastguard Worker }
2406*38e8c45fSAndroid Build Coastguard Worker
setDestinationFrame(const sp<SurfaceControl> & sc,const Rect & destinationFrame)2407*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDestinationFrame(
2408*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const Rect& destinationFrame) {
2409*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2410*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2411*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2412*38e8c45fSAndroid Build Coastguard Worker return *this;
2413*38e8c45fSAndroid Build Coastguard Worker }
2414*38e8c45fSAndroid Build Coastguard Worker
2415*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eDestinationFrameChanged;
2416*38e8c45fSAndroid Build Coastguard Worker s->destinationFrame = destinationFrame;
2417*38e8c45fSAndroid Build Coastguard Worker
2418*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2419*38e8c45fSAndroid Build Coastguard Worker return *this;
2420*38e8c45fSAndroid Build Coastguard Worker }
2421*38e8c45fSAndroid Build Coastguard Worker
setDropInputMode(const sp<SurfaceControl> & sc,gui::DropInputMode mode)2422*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDropInputMode(
2423*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, gui::DropInputMode mode) {
2424*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2425*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2426*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2427*38e8c45fSAndroid Build Coastguard Worker return *this;
2428*38e8c45fSAndroid Build Coastguard Worker }
2429*38e8c45fSAndroid Build Coastguard Worker
2430*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eDropInputModeChanged;
2431*38e8c45fSAndroid Build Coastguard Worker s->dropInputMode = mode;
2432*38e8c45fSAndroid Build Coastguard Worker
2433*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2434*38e8c45fSAndroid Build Coastguard Worker return *this;
2435*38e8c45fSAndroid Build Coastguard Worker }
2436*38e8c45fSAndroid Build Coastguard Worker
setBufferReleaseChannel(const sp<SurfaceControl> & sc,const std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> & channel)2437*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBufferReleaseChannel(
2438*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc,
2439*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint>& channel) {
2440*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2441*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2442*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2443*38e8c45fSAndroid Build Coastguard Worker return *this;
2444*38e8c45fSAndroid Build Coastguard Worker }
2445*38e8c45fSAndroid Build Coastguard Worker
2446*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eBufferReleaseChannelChanged;
2447*38e8c45fSAndroid Build Coastguard Worker s->bufferReleaseChannel = channel;
2448*38e8c45fSAndroid Build Coastguard Worker
2449*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2450*38e8c45fSAndroid Build Coastguard Worker return *this;
2451*38e8c45fSAndroid Build Coastguard Worker }
2452*38e8c45fSAndroid Build Coastguard Worker
setPictureProfileHandle(const sp<SurfaceControl> & sc,const PictureProfileHandle & pictureProfileHandle)2453*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setPictureProfileHandle(
2454*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, const PictureProfileHandle& pictureProfileHandle) {
2455*38e8c45fSAndroid Build Coastguard Worker if (com_android_graphics_libgui_flags_apply_picture_profiles()) {
2456*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2457*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2458*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2459*38e8c45fSAndroid Build Coastguard Worker return *this;
2460*38e8c45fSAndroid Build Coastguard Worker }
2461*38e8c45fSAndroid Build Coastguard Worker
2462*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::ePictureProfileHandleChanged;
2463*38e8c45fSAndroid Build Coastguard Worker s->pictureProfileHandle = pictureProfileHandle;
2464*38e8c45fSAndroid Build Coastguard Worker
2465*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2466*38e8c45fSAndroid Build Coastguard Worker }
2467*38e8c45fSAndroid Build Coastguard Worker return *this;
2468*38e8c45fSAndroid Build Coastguard Worker }
2469*38e8c45fSAndroid Build Coastguard Worker
setContentPriority(const sp<SurfaceControl> & sc,int32_t priority)2470*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setContentPriority(
2471*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, int32_t priority) {
2472*38e8c45fSAndroid Build Coastguard Worker if (com_android_graphics_libgui_flags_apply_picture_profiles()) {
2473*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2474*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2475*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2476*38e8c45fSAndroid Build Coastguard Worker return *this;
2477*38e8c45fSAndroid Build Coastguard Worker }
2478*38e8c45fSAndroid Build Coastguard Worker
2479*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eAppContentPriorityChanged;
2480*38e8c45fSAndroid Build Coastguard Worker s->appContentPriority = priority;
2481*38e8c45fSAndroid Build Coastguard Worker
2482*38e8c45fSAndroid Build Coastguard Worker registerSurfaceControlForCallback(sc);
2483*38e8c45fSAndroid Build Coastguard Worker }
2484*38e8c45fSAndroid Build Coastguard Worker return *this;
2485*38e8c45fSAndroid Build Coastguard Worker }
2486*38e8c45fSAndroid Build Coastguard Worker
2487*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------
2488*38e8c45fSAndroid Build Coastguard Worker
getDisplayState(const sp<IBinder> & token)2489*38e8c45fSAndroid Build Coastguard Worker DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {
2490*38e8c45fSAndroid Build Coastguard Worker DisplayState s;
2491*38e8c45fSAndroid Build Coastguard Worker s.token = token;
2492*38e8c45fSAndroid Build Coastguard Worker ssize_t index = mDisplayStates.indexOf(s);
2493*38e8c45fSAndroid Build Coastguard Worker if (index < 0) {
2494*38e8c45fSAndroid Build Coastguard Worker // we don't have it, add an initialized layer_state to our list
2495*38e8c45fSAndroid Build Coastguard Worker s.what = 0;
2496*38e8c45fSAndroid Build Coastguard Worker index = mDisplayStates.add(s);
2497*38e8c45fSAndroid Build Coastguard Worker }
2498*38e8c45fSAndroid Build Coastguard Worker return mDisplayStates.editItemAt(static_cast<size_t>(index));
2499*38e8c45fSAndroid Build Coastguard Worker }
2500*38e8c45fSAndroid Build Coastguard Worker
setDisplaySurface(const sp<IBinder> & token,const sp<IGraphicBufferProducer> & bufferProducer)2501*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::Transaction::setDisplaySurface(const sp<IBinder>& token,
2502*38e8c45fSAndroid Build Coastguard Worker const sp<IGraphicBufferProducer>& bufferProducer) {
2503*38e8c45fSAndroid Build Coastguard Worker if (bufferProducer.get() != nullptr) {
2504*38e8c45fSAndroid Build Coastguard Worker // Make sure that composition can never be stalled by a virtual display
2505*38e8c45fSAndroid Build Coastguard Worker // consumer that isn't processing buffers fast enough.
2506*38e8c45fSAndroid Build Coastguard Worker status_t err = bufferProducer->setAsyncMode(true);
2507*38e8c45fSAndroid Build Coastguard Worker if (err != NO_ERROR) {
2508*38e8c45fSAndroid Build Coastguard Worker ALOGE("Composer::setDisplaySurface Failed to enable async mode on the "
2509*38e8c45fSAndroid Build Coastguard Worker "BufferQueue. This BufferQueue cannot be used for virtual "
2510*38e8c45fSAndroid Build Coastguard Worker "display. (%d)", err);
2511*38e8c45fSAndroid Build Coastguard Worker return err;
2512*38e8c45fSAndroid Build Coastguard Worker }
2513*38e8c45fSAndroid Build Coastguard Worker }
2514*38e8c45fSAndroid Build Coastguard Worker DisplayState& s(getDisplayState(token));
2515*38e8c45fSAndroid Build Coastguard Worker s.surface = bufferProducer;
2516*38e8c45fSAndroid Build Coastguard Worker s.what |= DisplayState::eSurfaceChanged;
2517*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
2518*38e8c45fSAndroid Build Coastguard Worker }
2519*38e8c45fSAndroid Build Coastguard Worker
setDisplayLayerStack(const sp<IBinder> & token,ui::LayerStack layerStack)2520*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::setDisplayLayerStack(const sp<IBinder>& token,
2521*38e8c45fSAndroid Build Coastguard Worker ui::LayerStack layerStack) {
2522*38e8c45fSAndroid Build Coastguard Worker DisplayState& s(getDisplayState(token));
2523*38e8c45fSAndroid Build Coastguard Worker s.layerStack = layerStack;
2524*38e8c45fSAndroid Build Coastguard Worker s.what |= DisplayState::eLayerStackChanged;
2525*38e8c45fSAndroid Build Coastguard Worker }
2526*38e8c45fSAndroid Build Coastguard Worker
setDisplayFlags(const sp<IBinder> & token,uint32_t flags)2527*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::setDisplayFlags(const sp<IBinder>& token, uint32_t flags) {
2528*38e8c45fSAndroid Build Coastguard Worker DisplayState& s(getDisplayState(token));
2529*38e8c45fSAndroid Build Coastguard Worker s.flags = flags;
2530*38e8c45fSAndroid Build Coastguard Worker s.what |= DisplayState::eFlagsChanged;
2531*38e8c45fSAndroid Build Coastguard Worker }
2532*38e8c45fSAndroid Build Coastguard Worker
setDisplayProjection(const sp<IBinder> & token,ui::Rotation orientation,const Rect & layerStackRect,const Rect & displayRect)2533*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::setDisplayProjection(const sp<IBinder>& token,
2534*38e8c45fSAndroid Build Coastguard Worker ui::Rotation orientation,
2535*38e8c45fSAndroid Build Coastguard Worker const Rect& layerStackRect,
2536*38e8c45fSAndroid Build Coastguard Worker const Rect& displayRect) {
2537*38e8c45fSAndroid Build Coastguard Worker DisplayState& s(getDisplayState(token));
2538*38e8c45fSAndroid Build Coastguard Worker s.orientation = orientation;
2539*38e8c45fSAndroid Build Coastguard Worker s.layerStackSpaceRect = layerStackRect;
2540*38e8c45fSAndroid Build Coastguard Worker s.orientedDisplaySpaceRect = displayRect;
2541*38e8c45fSAndroid Build Coastguard Worker s.what |= DisplayState::eDisplayProjectionChanged;
2542*38e8c45fSAndroid Build Coastguard Worker }
2543*38e8c45fSAndroid Build Coastguard Worker
setDisplaySize(const sp<IBinder> & token,uint32_t width,uint32_t height)2544*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) {
2545*38e8c45fSAndroid Build Coastguard Worker DisplayState& s(getDisplayState(token));
2546*38e8c45fSAndroid Build Coastguard Worker s.width = width;
2547*38e8c45fSAndroid Build Coastguard Worker s.height = height;
2548*38e8c45fSAndroid Build Coastguard Worker s.what |= DisplayState::eDisplaySizeChanged;
2549*38e8c45fSAndroid Build Coastguard Worker }
2550*38e8c45fSAndroid Build Coastguard Worker
2551*38e8c45fSAndroid Build Coastguard Worker // copied from FrameTimelineInfo::merge()
mergeFrameTimelineInfo(FrameTimelineInfo & t,const FrameTimelineInfo & other)2552*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::Transaction::mergeFrameTimelineInfo(FrameTimelineInfo& t,
2553*38e8c45fSAndroid Build Coastguard Worker const FrameTimelineInfo& other) {
2554*38e8c45fSAndroid Build Coastguard Worker // When merging vsync Ids we take the oldest valid one
2555*38e8c45fSAndroid Build Coastguard Worker if (t.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID &&
2556*38e8c45fSAndroid Build Coastguard Worker other.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) {
2557*38e8c45fSAndroid Build Coastguard Worker if (other.vsyncId > t.vsyncId) {
2558*38e8c45fSAndroid Build Coastguard Worker t = other;
2559*38e8c45fSAndroid Build Coastguard Worker }
2560*38e8c45fSAndroid Build Coastguard Worker } else if (t.vsyncId == FrameTimelineInfo::INVALID_VSYNC_ID) {
2561*38e8c45fSAndroid Build Coastguard Worker t = other;
2562*38e8c45fSAndroid Build Coastguard Worker }
2563*38e8c45fSAndroid Build Coastguard Worker }
2564*38e8c45fSAndroid Build Coastguard Worker
2565*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction&
setTrustedPresentationCallback(const sp<SurfaceControl> & sc,TrustedPresentationCallback cb,const TrustedPresentationThresholds & thresholds,void * context,sp<SurfaceComposerClient::PresentationCallbackRAII> & outCallbackRef)2566*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction::setTrustedPresentationCallback(
2567*38e8c45fSAndroid Build Coastguard Worker const sp<SurfaceControl>& sc, TrustedPresentationCallback cb,
2568*38e8c45fSAndroid Build Coastguard Worker const TrustedPresentationThresholds& thresholds, void* context,
2569*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceComposerClient::PresentationCallbackRAII>& outCallbackRef) {
2570*38e8c45fSAndroid Build Coastguard Worker outCallbackRef =
2571*38e8c45fSAndroid Build Coastguard Worker mTransactionCompletedListener->addTrustedPresentationCallback(cb, sc->getLayerId(),
2572*38e8c45fSAndroid Build Coastguard Worker context);
2573*38e8c45fSAndroid Build Coastguard Worker
2574*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2575*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2576*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2577*38e8c45fSAndroid Build Coastguard Worker return *this;
2578*38e8c45fSAndroid Build Coastguard Worker }
2579*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eTrustedPresentationInfoChanged;
2580*38e8c45fSAndroid Build Coastguard Worker s->trustedPresentationThresholds = thresholds;
2581*38e8c45fSAndroid Build Coastguard Worker s->trustedPresentationListener.callbackInterface = TransactionCompletedListener::getIInstance();
2582*38e8c45fSAndroid Build Coastguard Worker s->trustedPresentationListener.callbackId = sc->getLayerId();
2583*38e8c45fSAndroid Build Coastguard Worker
2584*38e8c45fSAndroid Build Coastguard Worker return *this;
2585*38e8c45fSAndroid Build Coastguard Worker }
2586*38e8c45fSAndroid Build Coastguard Worker
2587*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction&
clearTrustedPresentationCallback(const sp<SurfaceControl> & sc)2588*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::Transaction::clearTrustedPresentationCallback(const sp<SurfaceControl>& sc) {
2589*38e8c45fSAndroid Build Coastguard Worker mTransactionCompletedListener->clearTrustedPresentationCallback(sc->getLayerId());
2590*38e8c45fSAndroid Build Coastguard Worker
2591*38e8c45fSAndroid Build Coastguard Worker layer_state_t* s = getLayerState(sc);
2592*38e8c45fSAndroid Build Coastguard Worker if (!s) {
2593*38e8c45fSAndroid Build Coastguard Worker mStatus = BAD_INDEX;
2594*38e8c45fSAndroid Build Coastguard Worker return *this;
2595*38e8c45fSAndroid Build Coastguard Worker }
2596*38e8c45fSAndroid Build Coastguard Worker s->what |= layer_state_t::eTrustedPresentationInfoChanged;
2597*38e8c45fSAndroid Build Coastguard Worker s->trustedPresentationThresholds = TrustedPresentationThresholds();
2598*38e8c45fSAndroid Build Coastguard Worker s->trustedPresentationListener.callbackInterface = nullptr;
2599*38e8c45fSAndroid Build Coastguard Worker s->trustedPresentationListener.callbackId = -1;
2600*38e8c45fSAndroid Build Coastguard Worker
2601*38e8c45fSAndroid Build Coastguard Worker return *this;
2602*38e8c45fSAndroid Build Coastguard Worker }
2603*38e8c45fSAndroid Build Coastguard Worker
2604*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------
2605*38e8c45fSAndroid Build Coastguard Worker
SurfaceComposerClient()2606*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::SurfaceComposerClient() : mStatus(NO_INIT) {}
2607*38e8c45fSAndroid Build Coastguard Worker
SurfaceComposerClient(const sp<ISurfaceComposerClient> & client)2608*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::SurfaceComposerClient(const sp<ISurfaceComposerClient>& client)
2609*38e8c45fSAndroid Build Coastguard Worker : mStatus(NO_ERROR), mClient(client) {}
2610*38e8c45fSAndroid Build Coastguard Worker
onFirstRef()2611*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::onFirstRef() {
2612*38e8c45fSAndroid Build Coastguard Worker sp<gui::ISurfaceComposer> sf(ComposerServiceAIDL::getComposerService());
2613*38e8c45fSAndroid Build Coastguard Worker if (sf != nullptr && mStatus == NO_INIT) {
2614*38e8c45fSAndroid Build Coastguard Worker sp<ISurfaceComposerClient> conn;
2615*38e8c45fSAndroid Build Coastguard Worker binder::Status status = sf->createConnection(&conn);
2616*38e8c45fSAndroid Build Coastguard Worker if (status.isOk() && conn != nullptr) {
2617*38e8c45fSAndroid Build Coastguard Worker mClient = conn;
2618*38e8c45fSAndroid Build Coastguard Worker mStatus = NO_ERROR;
2619*38e8c45fSAndroid Build Coastguard Worker }
2620*38e8c45fSAndroid Build Coastguard Worker }
2621*38e8c45fSAndroid Build Coastguard Worker }
2622*38e8c45fSAndroid Build Coastguard Worker
~SurfaceComposerClient()2623*38e8c45fSAndroid Build Coastguard Worker SurfaceComposerClient::~SurfaceComposerClient() {
2624*38e8c45fSAndroid Build Coastguard Worker dispose();
2625*38e8c45fSAndroid Build Coastguard Worker }
2626*38e8c45fSAndroid Build Coastguard Worker
initCheck() const2627*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::initCheck() const {
2628*38e8c45fSAndroid Build Coastguard Worker return mStatus;
2629*38e8c45fSAndroid Build Coastguard Worker }
2630*38e8c45fSAndroid Build Coastguard Worker
connection() const2631*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> SurfaceComposerClient::connection() const {
2632*38e8c45fSAndroid Build Coastguard Worker return IInterface::asBinder(mClient);
2633*38e8c45fSAndroid Build Coastguard Worker }
2634*38e8c45fSAndroid Build Coastguard Worker
linkToComposerDeath(const sp<IBinder::DeathRecipient> & recipient,void * cookie,uint32_t flags)2635*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::linkToComposerDeath(
2636*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder::DeathRecipient>& recipient,
2637*38e8c45fSAndroid Build Coastguard Worker void* cookie, uint32_t flags) {
2638*38e8c45fSAndroid Build Coastguard Worker sp<ISurfaceComposer> sf(ComposerService::getComposerService());
2639*38e8c45fSAndroid Build Coastguard Worker return IInterface::asBinder(sf)->linkToDeath(recipient, cookie, flags);
2640*38e8c45fSAndroid Build Coastguard Worker }
2641*38e8c45fSAndroid Build Coastguard Worker
dispose()2642*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::dispose() {
2643*38e8c45fSAndroid Build Coastguard Worker // this can be called more than once.
2644*38e8c45fSAndroid Build Coastguard Worker sp<ISurfaceComposerClient> client;
2645*38e8c45fSAndroid Build Coastguard Worker Mutex::Autolock _lm(mLock);
2646*38e8c45fSAndroid Build Coastguard Worker if (mClient != nullptr) {
2647*38e8c45fSAndroid Build Coastguard Worker client = mClient; // hold ref while lock is held
2648*38e8c45fSAndroid Build Coastguard Worker mClient.clear();
2649*38e8c45fSAndroid Build Coastguard Worker }
2650*38e8c45fSAndroid Build Coastguard Worker mStatus = NO_INIT;
2651*38e8c45fSAndroid Build Coastguard Worker }
2652*38e8c45fSAndroid Build Coastguard Worker
bootFinished()2653*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::bootFinished() {
2654*38e8c45fSAndroid Build Coastguard Worker sp<gui::ISurfaceComposer> sf(ComposerServiceAIDL::getComposerService());
2655*38e8c45fSAndroid Build Coastguard Worker binder::Status status = sf->bootFinished();
2656*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2657*38e8c45fSAndroid Build Coastguard Worker }
2658*38e8c45fSAndroid Build Coastguard Worker
createSurface(const String8 & name,uint32_t w,uint32_t h,PixelFormat format,int32_t flags,const sp<IBinder> & parentHandle,LayerMetadata metadata,uint32_t * outTransformHint)2659*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceControl> SurfaceComposerClient::createSurface(const String8& name, uint32_t w, uint32_t h,
2660*38e8c45fSAndroid Build Coastguard Worker PixelFormat format, int32_t flags,
2661*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& parentHandle,
2662*38e8c45fSAndroid Build Coastguard Worker LayerMetadata metadata,
2663*38e8c45fSAndroid Build Coastguard Worker uint32_t* outTransformHint) {
2664*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceControl> s;
2665*38e8c45fSAndroid Build Coastguard Worker createSurfaceChecked(name, w, h, format, &s, flags, parentHandle, std::move(metadata),
2666*38e8c45fSAndroid Build Coastguard Worker outTransformHint);
2667*38e8c45fSAndroid Build Coastguard Worker return s;
2668*38e8c45fSAndroid Build Coastguard Worker }
2669*38e8c45fSAndroid Build Coastguard Worker
toString(const String16 & string)2670*38e8c45fSAndroid Build Coastguard Worker static std::string toString(const String16& string) {
2671*38e8c45fSAndroid Build Coastguard Worker return std::string(String8(string).c_str());
2672*38e8c45fSAndroid Build Coastguard Worker }
2673*38e8c45fSAndroid Build Coastguard Worker
createSurfaceChecked(const String8 & name,uint32_t w,uint32_t h,PixelFormat format,sp<SurfaceControl> * outSurface,int32_t flags,const sp<IBinder> & parentHandle,LayerMetadata metadata,uint32_t * outTransformHint)2674*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::createSurfaceChecked(const String8& name, uint32_t w, uint32_t h,
2675*38e8c45fSAndroid Build Coastguard Worker PixelFormat format,
2676*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceControl>* outSurface, int32_t flags,
2677*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& parentHandle,
2678*38e8c45fSAndroid Build Coastguard Worker LayerMetadata metadata,
2679*38e8c45fSAndroid Build Coastguard Worker uint32_t* outTransformHint) {
2680*38e8c45fSAndroid Build Coastguard Worker status_t err = mStatus;
2681*38e8c45fSAndroid Build Coastguard Worker
2682*38e8c45fSAndroid Build Coastguard Worker if (mStatus == NO_ERROR) {
2683*38e8c45fSAndroid Build Coastguard Worker gui::CreateSurfaceResult result;
2684*38e8c45fSAndroid Build Coastguard Worker binder::Status status = mClient->createSurface(std::string(name.c_str()), flags,
2685*38e8c45fSAndroid Build Coastguard Worker parentHandle, std::move(metadata), &result);
2686*38e8c45fSAndroid Build Coastguard Worker err = statusTFromBinderStatus(status);
2687*38e8c45fSAndroid Build Coastguard Worker if (outTransformHint) {
2688*38e8c45fSAndroid Build Coastguard Worker *outTransformHint = result.transformHint;
2689*38e8c45fSAndroid Build Coastguard Worker }
2690*38e8c45fSAndroid Build Coastguard Worker ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
2691*38e8c45fSAndroid Build Coastguard Worker if (err == NO_ERROR) {
2692*38e8c45fSAndroid Build Coastguard Worker *outSurface = new SurfaceControl(this, result.handle, result.layerId,
2693*38e8c45fSAndroid Build Coastguard Worker toString(result.layerName), w, h, format,
2694*38e8c45fSAndroid Build Coastguard Worker result.transformHint, flags);
2695*38e8c45fSAndroid Build Coastguard Worker }
2696*38e8c45fSAndroid Build Coastguard Worker }
2697*38e8c45fSAndroid Build Coastguard Worker return err;
2698*38e8c45fSAndroid Build Coastguard Worker }
2699*38e8c45fSAndroid Build Coastguard Worker
mirrorSurface(SurfaceControl * mirrorFromSurface)2700*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceControl> SurfaceComposerClient::mirrorSurface(SurfaceControl* mirrorFromSurface) {
2701*38e8c45fSAndroid Build Coastguard Worker if (mirrorFromSurface == nullptr) {
2702*38e8c45fSAndroid Build Coastguard Worker return nullptr;
2703*38e8c45fSAndroid Build Coastguard Worker }
2704*38e8c45fSAndroid Build Coastguard Worker
2705*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> mirrorFromHandle = mirrorFromSurface->getHandle();
2706*38e8c45fSAndroid Build Coastguard Worker gui::CreateSurfaceResult result;
2707*38e8c45fSAndroid Build Coastguard Worker const binder::Status status = mClient->mirrorSurface(mirrorFromHandle, &result);
2708*38e8c45fSAndroid Build Coastguard Worker const status_t err = statusTFromBinderStatus(status);
2709*38e8c45fSAndroid Build Coastguard Worker if (err == NO_ERROR) {
2710*38e8c45fSAndroid Build Coastguard Worker return new SurfaceControl(this, result.handle, result.layerId, toString(result.layerName));
2711*38e8c45fSAndroid Build Coastguard Worker }
2712*38e8c45fSAndroid Build Coastguard Worker return nullptr;
2713*38e8c45fSAndroid Build Coastguard Worker }
2714*38e8c45fSAndroid Build Coastguard Worker
mirrorDisplay(DisplayId displayId)2715*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceControl> SurfaceComposerClient::mirrorDisplay(DisplayId displayId) {
2716*38e8c45fSAndroid Build Coastguard Worker gui::CreateSurfaceResult result;
2717*38e8c45fSAndroid Build Coastguard Worker const binder::Status status = mClient->mirrorDisplay(displayId.value, &result);
2718*38e8c45fSAndroid Build Coastguard Worker const status_t err = statusTFromBinderStatus(status);
2719*38e8c45fSAndroid Build Coastguard Worker if (err == NO_ERROR) {
2720*38e8c45fSAndroid Build Coastguard Worker return new SurfaceControl(this, result.handle, result.layerId, toString(result.layerName));
2721*38e8c45fSAndroid Build Coastguard Worker }
2722*38e8c45fSAndroid Build Coastguard Worker return nullptr;
2723*38e8c45fSAndroid Build Coastguard Worker }
2724*38e8c45fSAndroid Build Coastguard Worker
clearLayerFrameStats(const sp<IBinder> & token) const2725*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const {
2726*38e8c45fSAndroid Build Coastguard Worker if (mStatus != NO_ERROR) {
2727*38e8c45fSAndroid Build Coastguard Worker return mStatus;
2728*38e8c45fSAndroid Build Coastguard Worker }
2729*38e8c45fSAndroid Build Coastguard Worker const binder::Status status = mClient->clearLayerFrameStats(token);
2730*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2731*38e8c45fSAndroid Build Coastguard Worker }
2732*38e8c45fSAndroid Build Coastguard Worker
getLayerFrameStats(const sp<IBinder> & token,FrameStats * outStats) const2733*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,
2734*38e8c45fSAndroid Build Coastguard Worker FrameStats* outStats) const {
2735*38e8c45fSAndroid Build Coastguard Worker if (mStatus != NO_ERROR) {
2736*38e8c45fSAndroid Build Coastguard Worker return mStatus;
2737*38e8c45fSAndroid Build Coastguard Worker }
2738*38e8c45fSAndroid Build Coastguard Worker gui::FrameStats stats;
2739*38e8c45fSAndroid Build Coastguard Worker const binder::Status status = mClient->getLayerFrameStats(token, &stats);
2740*38e8c45fSAndroid Build Coastguard Worker if (status.isOk()) {
2741*38e8c45fSAndroid Build Coastguard Worker outStats->refreshPeriodNano = stats.refreshPeriodNano;
2742*38e8c45fSAndroid Build Coastguard Worker outStats->desiredPresentTimesNano.setCapacity(stats.desiredPresentTimesNano.size());
2743*38e8c45fSAndroid Build Coastguard Worker for (const auto& t : stats.desiredPresentTimesNano) {
2744*38e8c45fSAndroid Build Coastguard Worker outStats->desiredPresentTimesNano.add(t);
2745*38e8c45fSAndroid Build Coastguard Worker }
2746*38e8c45fSAndroid Build Coastguard Worker outStats->actualPresentTimesNano.setCapacity(stats.actualPresentTimesNano.size());
2747*38e8c45fSAndroid Build Coastguard Worker for (const auto& t : stats.actualPresentTimesNano) {
2748*38e8c45fSAndroid Build Coastguard Worker outStats->actualPresentTimesNano.add(t);
2749*38e8c45fSAndroid Build Coastguard Worker }
2750*38e8c45fSAndroid Build Coastguard Worker outStats->frameReadyTimesNano.setCapacity(stats.frameReadyTimesNano.size());
2751*38e8c45fSAndroid Build Coastguard Worker for (const auto& t : stats.frameReadyTimesNano) {
2752*38e8c45fSAndroid Build Coastguard Worker outStats->frameReadyTimesNano.add(t);
2753*38e8c45fSAndroid Build Coastguard Worker }
2754*38e8c45fSAndroid Build Coastguard Worker }
2755*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2756*38e8c45fSAndroid Build Coastguard Worker }
2757*38e8c45fSAndroid Build Coastguard Worker
2758*38e8c45fSAndroid Build Coastguard Worker // ----------------------------------------------------------------------------
2759*38e8c45fSAndroid Build Coastguard Worker
getDisplayState(const sp<IBinder> & display,ui::DisplayState * state)2760*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getDisplayState(const sp<IBinder>& display,
2761*38e8c45fSAndroid Build Coastguard Worker ui::DisplayState* state) {
2762*38e8c45fSAndroid Build Coastguard Worker gui::DisplayState ds;
2763*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
2764*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getDisplayState(display, &ds);
2765*38e8c45fSAndroid Build Coastguard Worker if (status.isOk()) {
2766*38e8c45fSAndroid Build Coastguard Worker state->layerStack = ui::LayerStack::fromValue(ds.layerStack);
2767*38e8c45fSAndroid Build Coastguard Worker state->orientation = static_cast<ui::Rotation>(ds.orientation);
2768*38e8c45fSAndroid Build Coastguard Worker state->layerStackSpaceRect =
2769*38e8c45fSAndroid Build Coastguard Worker ui::Size(ds.layerStackSpaceRect.width, ds.layerStackSpaceRect.height);
2770*38e8c45fSAndroid Build Coastguard Worker }
2771*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2772*38e8c45fSAndroid Build Coastguard Worker }
2773*38e8c45fSAndroid Build Coastguard Worker
getStaticDisplayInfo(int64_t displayId,ui::StaticDisplayInfo * outInfo)2774*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getStaticDisplayInfo(int64_t displayId,
2775*38e8c45fSAndroid Build Coastguard Worker ui::StaticDisplayInfo* outInfo) {
2776*38e8c45fSAndroid Build Coastguard Worker using Tag = android::gui::DeviceProductInfo::ManufactureOrModelDate::Tag;
2777*38e8c45fSAndroid Build Coastguard Worker gui::StaticDisplayInfo ginfo;
2778*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
2779*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getStaticDisplayInfo(displayId, &ginfo);
2780*38e8c45fSAndroid Build Coastguard Worker if (status.isOk()) {
2781*38e8c45fSAndroid Build Coastguard Worker // convert gui::StaticDisplayInfo to ui::StaticDisplayInfo
2782*38e8c45fSAndroid Build Coastguard Worker outInfo->connectionType = static_cast<ui::DisplayConnectionType>(ginfo.connectionType);
2783*38e8c45fSAndroid Build Coastguard Worker outInfo->density = ginfo.density;
2784*38e8c45fSAndroid Build Coastguard Worker outInfo->secure = ginfo.secure;
2785*38e8c45fSAndroid Build Coastguard Worker outInfo->installOrientation = static_cast<ui::Rotation>(ginfo.installOrientation);
2786*38e8c45fSAndroid Build Coastguard Worker
2787*38e8c45fSAndroid Build Coastguard Worker if (const std::optional<gui::DeviceProductInfo> dpi = ginfo.deviceProductInfo) {
2788*38e8c45fSAndroid Build Coastguard Worker DeviceProductInfo info;
2789*38e8c45fSAndroid Build Coastguard Worker info.name = dpi->name;
2790*38e8c45fSAndroid Build Coastguard Worker if (dpi->manufacturerPnpId.size() > 0) {
2791*38e8c45fSAndroid Build Coastguard Worker // copid from PnpId = std::array<char, 4> in ui/DeviceProductInfo.h
2792*38e8c45fSAndroid Build Coastguard Worker constexpr int kMaxPnpIdSize = 4;
2793*38e8c45fSAndroid Build Coastguard Worker size_t count = std::max<size_t>(kMaxPnpIdSize, dpi->manufacturerPnpId.size());
2794*38e8c45fSAndroid Build Coastguard Worker std::copy_n(dpi->manufacturerPnpId.begin(), count, info.manufacturerPnpId.begin());
2795*38e8c45fSAndroid Build Coastguard Worker }
2796*38e8c45fSAndroid Build Coastguard Worker if (dpi->relativeAddress.size() > 0) {
2797*38e8c45fSAndroid Build Coastguard Worker std::copy(dpi->relativeAddress.begin(), dpi->relativeAddress.end(),
2798*38e8c45fSAndroid Build Coastguard Worker std::back_inserter(info.relativeAddress));
2799*38e8c45fSAndroid Build Coastguard Worker }
2800*38e8c45fSAndroid Build Coastguard Worker info.productId = dpi->productId;
2801*38e8c45fSAndroid Build Coastguard Worker
2802*38e8c45fSAndroid Build Coastguard Worker const gui::DeviceProductInfo::ManufactureOrModelDate& date =
2803*38e8c45fSAndroid Build Coastguard Worker dpi->manufactureOrModelDate;
2804*38e8c45fSAndroid Build Coastguard Worker if (date.getTag() == Tag::modelYear) {
2805*38e8c45fSAndroid Build Coastguard Worker DeviceProductInfo::ModelYear modelYear;
2806*38e8c45fSAndroid Build Coastguard Worker modelYear.year = static_cast<uint32_t>(date.get<Tag::modelYear>().year);
2807*38e8c45fSAndroid Build Coastguard Worker info.manufactureOrModelDate = modelYear;
2808*38e8c45fSAndroid Build Coastguard Worker } else if (date.getTag() == Tag::manufactureYear) {
2809*38e8c45fSAndroid Build Coastguard Worker DeviceProductInfo::ManufactureYear manufactureYear;
2810*38e8c45fSAndroid Build Coastguard Worker manufactureYear.year = date.get<Tag::manufactureYear>().modelYear.year;
2811*38e8c45fSAndroid Build Coastguard Worker info.manufactureOrModelDate = manufactureYear;
2812*38e8c45fSAndroid Build Coastguard Worker } else if (date.getTag() == Tag::manufactureWeekAndYear) {
2813*38e8c45fSAndroid Build Coastguard Worker DeviceProductInfo::ManufactureWeekAndYear weekAndYear;
2814*38e8c45fSAndroid Build Coastguard Worker weekAndYear.year =
2815*38e8c45fSAndroid Build Coastguard Worker date.get<Tag::manufactureWeekAndYear>().manufactureYear.modelYear.year;
2816*38e8c45fSAndroid Build Coastguard Worker weekAndYear.week = date.get<Tag::manufactureWeekAndYear>().week;
2817*38e8c45fSAndroid Build Coastguard Worker info.manufactureOrModelDate = weekAndYear;
2818*38e8c45fSAndroid Build Coastguard Worker }
2819*38e8c45fSAndroid Build Coastguard Worker
2820*38e8c45fSAndroid Build Coastguard Worker outInfo->deviceProductInfo = info;
2821*38e8c45fSAndroid Build Coastguard Worker }
2822*38e8c45fSAndroid Build Coastguard Worker }
2823*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2824*38e8c45fSAndroid Build Coastguard Worker }
2825*38e8c45fSAndroid Build Coastguard Worker
getDynamicDisplayInfoInternal(gui::DynamicDisplayInfo & ginfo,ui::DynamicDisplayInfo * & outInfo)2826*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::getDynamicDisplayInfoInternal(gui::DynamicDisplayInfo& ginfo,
2827*38e8c45fSAndroid Build Coastguard Worker ui::DynamicDisplayInfo*& outInfo) {
2828*38e8c45fSAndroid Build Coastguard Worker // convert gui::DynamicDisplayInfo to ui::DynamicDisplayInfo
2829*38e8c45fSAndroid Build Coastguard Worker outInfo->supportedDisplayModes.clear();
2830*38e8c45fSAndroid Build Coastguard Worker outInfo->supportedDisplayModes.reserve(ginfo.supportedDisplayModes.size());
2831*38e8c45fSAndroid Build Coastguard Worker for (const auto& mode : ginfo.supportedDisplayModes) {
2832*38e8c45fSAndroid Build Coastguard Worker ui::DisplayMode outMode;
2833*38e8c45fSAndroid Build Coastguard Worker outMode.id = mode.id;
2834*38e8c45fSAndroid Build Coastguard Worker outMode.resolution.width = mode.resolution.width;
2835*38e8c45fSAndroid Build Coastguard Worker outMode.resolution.height = mode.resolution.height;
2836*38e8c45fSAndroid Build Coastguard Worker outMode.xDpi = mode.xDpi;
2837*38e8c45fSAndroid Build Coastguard Worker outMode.yDpi = mode.yDpi;
2838*38e8c45fSAndroid Build Coastguard Worker outMode.peakRefreshRate = mode.peakRefreshRate;
2839*38e8c45fSAndroid Build Coastguard Worker outMode.vsyncRate = mode.vsyncRate;
2840*38e8c45fSAndroid Build Coastguard Worker outMode.appVsyncOffset = mode.appVsyncOffset;
2841*38e8c45fSAndroid Build Coastguard Worker outMode.sfVsyncOffset = mode.sfVsyncOffset;
2842*38e8c45fSAndroid Build Coastguard Worker outMode.presentationDeadline = mode.presentationDeadline;
2843*38e8c45fSAndroid Build Coastguard Worker outMode.group = mode.group;
2844*38e8c45fSAndroid Build Coastguard Worker std::transform(mode.supportedHdrTypes.begin(), mode.supportedHdrTypes.end(),
2845*38e8c45fSAndroid Build Coastguard Worker std::back_inserter(outMode.supportedHdrTypes),
2846*38e8c45fSAndroid Build Coastguard Worker [](const int32_t& value) { return static_cast<ui::Hdr>(value); });
2847*38e8c45fSAndroid Build Coastguard Worker outInfo->supportedDisplayModes.push_back(outMode);
2848*38e8c45fSAndroid Build Coastguard Worker }
2849*38e8c45fSAndroid Build Coastguard Worker
2850*38e8c45fSAndroid Build Coastguard Worker outInfo->activeDisplayModeId = ginfo.activeDisplayModeId;
2851*38e8c45fSAndroid Build Coastguard Worker outInfo->renderFrameRate = ginfo.renderFrameRate;
2852*38e8c45fSAndroid Build Coastguard Worker
2853*38e8c45fSAndroid Build Coastguard Worker outInfo->supportedColorModes.clear();
2854*38e8c45fSAndroid Build Coastguard Worker outInfo->supportedColorModes.reserve(ginfo.supportedColorModes.size());
2855*38e8c45fSAndroid Build Coastguard Worker for (const auto& cmode : ginfo.supportedColorModes) {
2856*38e8c45fSAndroid Build Coastguard Worker outInfo->supportedColorModes.push_back(static_cast<ui::ColorMode>(cmode));
2857*38e8c45fSAndroid Build Coastguard Worker }
2858*38e8c45fSAndroid Build Coastguard Worker
2859*38e8c45fSAndroid Build Coastguard Worker outInfo->activeColorMode = static_cast<ui::ColorMode>(ginfo.activeColorMode);
2860*38e8c45fSAndroid Build Coastguard Worker
2861*38e8c45fSAndroid Build Coastguard Worker std::vector<ui::Hdr> types;
2862*38e8c45fSAndroid Build Coastguard Worker types.reserve(ginfo.hdrCapabilities.supportedHdrTypes.size());
2863*38e8c45fSAndroid Build Coastguard Worker for (const auto& hdr : ginfo.hdrCapabilities.supportedHdrTypes) {
2864*38e8c45fSAndroid Build Coastguard Worker types.push_back(static_cast<ui::Hdr>(hdr));
2865*38e8c45fSAndroid Build Coastguard Worker }
2866*38e8c45fSAndroid Build Coastguard Worker outInfo->hdrCapabilities = HdrCapabilities(types, ginfo.hdrCapabilities.maxLuminance,
2867*38e8c45fSAndroid Build Coastguard Worker ginfo.hdrCapabilities.maxAverageLuminance,
2868*38e8c45fSAndroid Build Coastguard Worker ginfo.hdrCapabilities.minLuminance);
2869*38e8c45fSAndroid Build Coastguard Worker
2870*38e8c45fSAndroid Build Coastguard Worker outInfo->autoLowLatencyModeSupported = ginfo.autoLowLatencyModeSupported;
2871*38e8c45fSAndroid Build Coastguard Worker outInfo->gameContentTypeSupported = ginfo.gameContentTypeSupported;
2872*38e8c45fSAndroid Build Coastguard Worker outInfo->preferredBootDisplayMode = ginfo.preferredBootDisplayMode;
2873*38e8c45fSAndroid Build Coastguard Worker outInfo->hasArrSupport = ginfo.hasArrSupport;
2874*38e8c45fSAndroid Build Coastguard Worker outInfo->frameRateCategoryRate = ui::FrameRateCategoryRate(ginfo.frameRateCategoryRate.normal,
2875*38e8c45fSAndroid Build Coastguard Worker ginfo.frameRateCategoryRate.high);
2876*38e8c45fSAndroid Build Coastguard Worker outInfo->supportedRefreshRates.clear();
2877*38e8c45fSAndroid Build Coastguard Worker outInfo->supportedRefreshRates.reserve(ginfo.supportedRefreshRates.size());
2878*38e8c45fSAndroid Build Coastguard Worker for (const auto rate : ginfo.supportedRefreshRates) {
2879*38e8c45fSAndroid Build Coastguard Worker outInfo->supportedRefreshRates.push_back(static_cast<float>(rate));
2880*38e8c45fSAndroid Build Coastguard Worker }
2881*38e8c45fSAndroid Build Coastguard Worker }
2882*38e8c45fSAndroid Build Coastguard Worker
getDynamicDisplayInfoFromId(int64_t displayId,ui::DynamicDisplayInfo * outInfo)2883*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getDynamicDisplayInfoFromId(int64_t displayId,
2884*38e8c45fSAndroid Build Coastguard Worker ui::DynamicDisplayInfo* outInfo) {
2885*38e8c45fSAndroid Build Coastguard Worker gui::DynamicDisplayInfo ginfo;
2886*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
2887*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getDynamicDisplayInfoFromId(displayId,
2888*38e8c45fSAndroid Build Coastguard Worker &ginfo);
2889*38e8c45fSAndroid Build Coastguard Worker if (status.isOk()) {
2890*38e8c45fSAndroid Build Coastguard Worker getDynamicDisplayInfoInternal(ginfo, outInfo);
2891*38e8c45fSAndroid Build Coastguard Worker }
2892*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2893*38e8c45fSAndroid Build Coastguard Worker }
2894*38e8c45fSAndroid Build Coastguard Worker
getDynamicDisplayInfoFromToken(const sp<IBinder> & display,ui::DynamicDisplayInfo * outInfo)2895*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getDynamicDisplayInfoFromToken(const sp<IBinder>& display,
2896*38e8c45fSAndroid Build Coastguard Worker ui::DynamicDisplayInfo* outInfo) {
2897*38e8c45fSAndroid Build Coastguard Worker gui::DynamicDisplayInfo ginfo;
2898*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
2899*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getDynamicDisplayInfoFromToken(display,
2900*38e8c45fSAndroid Build Coastguard Worker &ginfo);
2901*38e8c45fSAndroid Build Coastguard Worker if (status.isOk()) {
2902*38e8c45fSAndroid Build Coastguard Worker getDynamicDisplayInfoInternal(ginfo, outInfo);
2903*38e8c45fSAndroid Build Coastguard Worker }
2904*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2905*38e8c45fSAndroid Build Coastguard Worker }
2906*38e8c45fSAndroid Build Coastguard Worker
getActiveDisplayMode(const sp<IBinder> & display,ui::DisplayMode * mode)2907*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getActiveDisplayMode(const sp<IBinder>& display,
2908*38e8c45fSAndroid Build Coastguard Worker ui::DisplayMode* mode) {
2909*38e8c45fSAndroid Build Coastguard Worker ui::DynamicDisplayInfo info;
2910*38e8c45fSAndroid Build Coastguard Worker
2911*38e8c45fSAndroid Build Coastguard Worker status_t result = getDynamicDisplayInfoFromToken(display, &info);
2912*38e8c45fSAndroid Build Coastguard Worker if (result != NO_ERROR) {
2913*38e8c45fSAndroid Build Coastguard Worker return result;
2914*38e8c45fSAndroid Build Coastguard Worker }
2915*38e8c45fSAndroid Build Coastguard Worker
2916*38e8c45fSAndroid Build Coastguard Worker if (const auto activeMode = info.getActiveDisplayMode()) {
2917*38e8c45fSAndroid Build Coastguard Worker *mode = *activeMode;
2918*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
2919*38e8c45fSAndroid Build Coastguard Worker }
2920*38e8c45fSAndroid Build Coastguard Worker
2921*38e8c45fSAndroid Build Coastguard Worker ALOGE("Active display mode not found.");
2922*38e8c45fSAndroid Build Coastguard Worker return NAME_NOT_FOUND;
2923*38e8c45fSAndroid Build Coastguard Worker }
2924*38e8c45fSAndroid Build Coastguard Worker
setDesiredDisplayModeSpecs(const sp<IBinder> & displayToken,const gui::DisplayModeSpecs & specs)2925*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken,
2926*38e8c45fSAndroid Build Coastguard Worker const gui::DisplayModeSpecs& specs) {
2927*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
2928*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->setDesiredDisplayModeSpecs(displayToken,
2929*38e8c45fSAndroid Build Coastguard Worker specs);
2930*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2931*38e8c45fSAndroid Build Coastguard Worker }
2932*38e8c45fSAndroid Build Coastguard Worker
getDesiredDisplayModeSpecs(const sp<IBinder> & displayToken,gui::DisplayModeSpecs * outSpecs)2933*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken,
2934*38e8c45fSAndroid Build Coastguard Worker gui::DisplayModeSpecs* outSpecs) {
2935*38e8c45fSAndroid Build Coastguard Worker if (!outSpecs) {
2936*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
2937*38e8c45fSAndroid Build Coastguard Worker }
2938*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
2939*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getDesiredDisplayModeSpecs(displayToken,
2940*38e8c45fSAndroid Build Coastguard Worker outSpecs);
2941*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2942*38e8c45fSAndroid Build Coastguard Worker }
2943*38e8c45fSAndroid Build Coastguard Worker
getDisplayNativePrimaries(const sp<IBinder> & display,ui::DisplayPrimaries & outPrimaries)2944*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getDisplayNativePrimaries(const sp<IBinder>& display,
2945*38e8c45fSAndroid Build Coastguard Worker ui::DisplayPrimaries& outPrimaries) {
2946*38e8c45fSAndroid Build Coastguard Worker gui::DisplayPrimaries primaries;
2947*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
2948*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getDisplayNativePrimaries(display,
2949*38e8c45fSAndroid Build Coastguard Worker &primaries);
2950*38e8c45fSAndroid Build Coastguard Worker if (status.isOk()) {
2951*38e8c45fSAndroid Build Coastguard Worker outPrimaries.red.X = primaries.red.X;
2952*38e8c45fSAndroid Build Coastguard Worker outPrimaries.red.Y = primaries.red.Y;
2953*38e8c45fSAndroid Build Coastguard Worker outPrimaries.red.Z = primaries.red.Z;
2954*38e8c45fSAndroid Build Coastguard Worker
2955*38e8c45fSAndroid Build Coastguard Worker outPrimaries.green.X = primaries.green.X;
2956*38e8c45fSAndroid Build Coastguard Worker outPrimaries.green.Y = primaries.green.Y;
2957*38e8c45fSAndroid Build Coastguard Worker outPrimaries.green.Z = primaries.green.Z;
2958*38e8c45fSAndroid Build Coastguard Worker
2959*38e8c45fSAndroid Build Coastguard Worker outPrimaries.blue.X = primaries.blue.X;
2960*38e8c45fSAndroid Build Coastguard Worker outPrimaries.blue.Y = primaries.blue.Y;
2961*38e8c45fSAndroid Build Coastguard Worker outPrimaries.blue.Z = primaries.blue.Z;
2962*38e8c45fSAndroid Build Coastguard Worker
2963*38e8c45fSAndroid Build Coastguard Worker outPrimaries.white.X = primaries.white.X;
2964*38e8c45fSAndroid Build Coastguard Worker outPrimaries.white.Y = primaries.white.Y;
2965*38e8c45fSAndroid Build Coastguard Worker outPrimaries.white.Z = primaries.white.Z;
2966*38e8c45fSAndroid Build Coastguard Worker }
2967*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2968*38e8c45fSAndroid Build Coastguard Worker }
2969*38e8c45fSAndroid Build Coastguard Worker
setActiveColorMode(const sp<IBinder> & display,ColorMode colorMode)2970*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display,
2971*38e8c45fSAndroid Build Coastguard Worker ColorMode colorMode) {
2972*38e8c45fSAndroid Build Coastguard Worker binder::Status status = ComposerServiceAIDL::getComposerService()
2973*38e8c45fSAndroid Build Coastguard Worker ->setActiveColorMode(display, static_cast<int>(colorMode));
2974*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2975*38e8c45fSAndroid Build Coastguard Worker }
2976*38e8c45fSAndroid Build Coastguard Worker
getBootDisplayModeSupport(bool * support)2977*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getBootDisplayModeSupport(bool* support) {
2978*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
2979*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getBootDisplayModeSupport(support);
2980*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2981*38e8c45fSAndroid Build Coastguard Worker }
2982*38e8c45fSAndroid Build Coastguard Worker
getOverlaySupport(gui::OverlayProperties * outProperties)2983*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getOverlaySupport(gui::OverlayProperties* outProperties) {
2984*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
2985*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getOverlaySupport(outProperties);
2986*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2987*38e8c45fSAndroid Build Coastguard Worker }
2988*38e8c45fSAndroid Build Coastguard Worker
setBootDisplayMode(const sp<IBinder> & display,ui::DisplayModeId displayModeId)2989*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::setBootDisplayMode(const sp<IBinder>& display,
2990*38e8c45fSAndroid Build Coastguard Worker ui::DisplayModeId displayModeId) {
2991*38e8c45fSAndroid Build Coastguard Worker binder::Status status = ComposerServiceAIDL::getComposerService()
2992*38e8c45fSAndroid Build Coastguard Worker ->setBootDisplayMode(display, static_cast<int>(displayModeId));
2993*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
2994*38e8c45fSAndroid Build Coastguard Worker }
2995*38e8c45fSAndroid Build Coastguard Worker
clearBootDisplayMode(const sp<IBinder> & display)2996*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::clearBootDisplayMode(const sp<IBinder>& display) {
2997*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
2998*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->clearBootDisplayMode(display);
2999*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3000*38e8c45fSAndroid Build Coastguard Worker }
3001*38e8c45fSAndroid Build Coastguard Worker
getHdrConversionCapabilities(std::vector<gui::HdrConversionCapability> * hdrConversionCapabilities)3002*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getHdrConversionCapabilities(
3003*38e8c45fSAndroid Build Coastguard Worker std::vector<gui::HdrConversionCapability>* hdrConversionCapabilities) {
3004*38e8c45fSAndroid Build Coastguard Worker binder::Status status = ComposerServiceAIDL::getComposerService()->getHdrConversionCapabilities(
3005*38e8c45fSAndroid Build Coastguard Worker hdrConversionCapabilities);
3006*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3007*38e8c45fSAndroid Build Coastguard Worker }
3008*38e8c45fSAndroid Build Coastguard Worker
setHdrConversionStrategy(gui::HdrConversionStrategy hdrConversionStrategy,ui::Hdr * outPreferredHdrOutputType)3009*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::setHdrConversionStrategy(
3010*38e8c45fSAndroid Build Coastguard Worker gui::HdrConversionStrategy hdrConversionStrategy, ui::Hdr* outPreferredHdrOutputType) {
3011*38e8c45fSAndroid Build Coastguard Worker int hdrType;
3012*38e8c45fSAndroid Build Coastguard Worker binder::Status status = ComposerServiceAIDL::getComposerService()
3013*38e8c45fSAndroid Build Coastguard Worker ->setHdrConversionStrategy(hdrConversionStrategy, &hdrType);
3014*38e8c45fSAndroid Build Coastguard Worker *outPreferredHdrOutputType = static_cast<ui::Hdr>(hdrType);
3015*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3016*38e8c45fSAndroid Build Coastguard Worker }
3017*38e8c45fSAndroid Build Coastguard Worker
getHdrOutputConversionSupport(bool * isSupported)3018*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getHdrOutputConversionSupport(bool* isSupported) {
3019*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3020*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getHdrOutputConversionSupport(isSupported);
3021*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3022*38e8c45fSAndroid Build Coastguard Worker }
3023*38e8c45fSAndroid Build Coastguard Worker
setGameModeFrameRateOverride(uid_t uid,float frameRate)3024*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::setGameModeFrameRateOverride(uid_t uid, float frameRate) {
3025*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3026*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->setGameModeFrameRateOverride(uid, frameRate);
3027*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3028*38e8c45fSAndroid Build Coastguard Worker }
3029*38e8c45fSAndroid Build Coastguard Worker
setGameDefaultFrameRateOverride(uid_t uid,float frameRate)3030*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::setGameDefaultFrameRateOverride(uid_t uid, float frameRate) {
3031*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3032*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->setGameDefaultFrameRateOverride(uid,
3033*38e8c45fSAndroid Build Coastguard Worker frameRate);
3034*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3035*38e8c45fSAndroid Build Coastguard Worker }
3036*38e8c45fSAndroid Build Coastguard Worker
updateSmallAreaDetection(std::vector<int32_t> & appIds,std::vector<float> & thresholds)3037*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::updateSmallAreaDetection(std::vector<int32_t>& appIds,
3038*38e8c45fSAndroid Build Coastguard Worker std::vector<float>& thresholds) {
3039*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3040*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->updateSmallAreaDetection(appIds, thresholds);
3041*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3042*38e8c45fSAndroid Build Coastguard Worker }
3043*38e8c45fSAndroid Build Coastguard Worker
setSmallAreaDetectionThreshold(int32_t appId,float threshold)3044*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::setSmallAreaDetectionThreshold(int32_t appId, float threshold) {
3045*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3046*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->setSmallAreaDetectionThreshold(appId,
3047*38e8c45fSAndroid Build Coastguard Worker threshold);
3048*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3049*38e8c45fSAndroid Build Coastguard Worker }
3050*38e8c45fSAndroid Build Coastguard Worker
setAutoLowLatencyMode(const sp<IBinder> & display,bool on)3051*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) {
3052*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->setAutoLowLatencyMode(display, on);
3053*38e8c45fSAndroid Build Coastguard Worker }
3054*38e8c45fSAndroid Build Coastguard Worker
setGameContentType(const sp<IBinder> & display,bool on)3055*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::setGameContentType(const sp<IBinder>& display, bool on) {
3056*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->setGameContentType(display, on);
3057*38e8c45fSAndroid Build Coastguard Worker }
3058*38e8c45fSAndroid Build Coastguard Worker
setDisplayPowerMode(const sp<IBinder> & token,int mode)3059*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token,
3060*38e8c45fSAndroid Build Coastguard Worker int mode) {
3061*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->setPowerMode(token, mode);
3062*38e8c45fSAndroid Build Coastguard Worker }
3063*38e8c45fSAndroid Build Coastguard Worker
getMaxLayerPictureProfiles(const sp<IBinder> & token,int32_t * outMaxProfiles)3064*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getMaxLayerPictureProfiles(const sp<IBinder>& token,
3065*38e8c45fSAndroid Build Coastguard Worker int32_t* outMaxProfiles) {
3066*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3067*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getMaxLayerPictureProfiles(token,
3068*38e8c45fSAndroid Build Coastguard Worker outMaxProfiles);
3069*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3070*38e8c45fSAndroid Build Coastguard Worker }
3071*38e8c45fSAndroid Build Coastguard Worker
getCompositionPreference(ui::Dataspace * defaultDataspace,ui::PixelFormat * defaultPixelFormat,ui::Dataspace * wideColorGamutDataspace,ui::PixelFormat * wideColorGamutPixelFormat)3072*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getCompositionPreference(
3073*38e8c45fSAndroid Build Coastguard Worker ui::Dataspace* defaultDataspace, ui::PixelFormat* defaultPixelFormat,
3074*38e8c45fSAndroid Build Coastguard Worker ui::Dataspace* wideColorGamutDataspace, ui::PixelFormat* wideColorGamutPixelFormat) {
3075*38e8c45fSAndroid Build Coastguard Worker gui::CompositionPreference pref;
3076*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3077*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getCompositionPreference(&pref);
3078*38e8c45fSAndroid Build Coastguard Worker if (status.isOk()) {
3079*38e8c45fSAndroid Build Coastguard Worker *defaultDataspace = static_cast<ui::Dataspace>(pref.defaultDataspace);
3080*38e8c45fSAndroid Build Coastguard Worker *defaultPixelFormat = static_cast<ui::PixelFormat>(pref.defaultPixelFormat);
3081*38e8c45fSAndroid Build Coastguard Worker *wideColorGamutDataspace = static_cast<ui::Dataspace>(pref.wideColorGamutDataspace);
3082*38e8c45fSAndroid Build Coastguard Worker *wideColorGamutPixelFormat = static_cast<ui::PixelFormat>(pref.wideColorGamutPixelFormat);
3083*38e8c45fSAndroid Build Coastguard Worker }
3084*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3085*38e8c45fSAndroid Build Coastguard Worker }
3086*38e8c45fSAndroid Build Coastguard Worker
getProtectedContentSupport()3087*38e8c45fSAndroid Build Coastguard Worker bool SurfaceComposerClient::getProtectedContentSupport() {
3088*38e8c45fSAndroid Build Coastguard Worker bool supported = false;
3089*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getProtectedContentSupport(&supported);
3090*38e8c45fSAndroid Build Coastguard Worker return supported;
3091*38e8c45fSAndroid Build Coastguard Worker }
3092*38e8c45fSAndroid Build Coastguard Worker
clearAnimationFrameStats()3093*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::clearAnimationFrameStats() {
3094*38e8c45fSAndroid Build Coastguard Worker binder::Status status = ComposerServiceAIDL::getComposerService()->clearAnimationFrameStats();
3095*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3096*38e8c45fSAndroid Build Coastguard Worker }
3097*38e8c45fSAndroid Build Coastguard Worker
getAnimationFrameStats(FrameStats * outStats)3098*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) {
3099*38e8c45fSAndroid Build Coastguard Worker gui::FrameStats stats;
3100*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3101*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getAnimationFrameStats(&stats);
3102*38e8c45fSAndroid Build Coastguard Worker if (status.isOk()) {
3103*38e8c45fSAndroid Build Coastguard Worker outStats->refreshPeriodNano = stats.refreshPeriodNano;
3104*38e8c45fSAndroid Build Coastguard Worker outStats->desiredPresentTimesNano.setCapacity(stats.desiredPresentTimesNano.size());
3105*38e8c45fSAndroid Build Coastguard Worker for (const auto& t : stats.desiredPresentTimesNano) {
3106*38e8c45fSAndroid Build Coastguard Worker outStats->desiredPresentTimesNano.add(t);
3107*38e8c45fSAndroid Build Coastguard Worker }
3108*38e8c45fSAndroid Build Coastguard Worker outStats->actualPresentTimesNano.setCapacity(stats.actualPresentTimesNano.size());
3109*38e8c45fSAndroid Build Coastguard Worker for (const auto& t : stats.actualPresentTimesNano) {
3110*38e8c45fSAndroid Build Coastguard Worker outStats->actualPresentTimesNano.add(t);
3111*38e8c45fSAndroid Build Coastguard Worker }
3112*38e8c45fSAndroid Build Coastguard Worker outStats->frameReadyTimesNano.setCapacity(stats.frameReadyTimesNano.size());
3113*38e8c45fSAndroid Build Coastguard Worker for (const auto& t : stats.frameReadyTimesNano) {
3114*38e8c45fSAndroid Build Coastguard Worker outStats->frameReadyTimesNano.add(t);
3115*38e8c45fSAndroid Build Coastguard Worker }
3116*38e8c45fSAndroid Build Coastguard Worker }
3117*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3118*38e8c45fSAndroid Build Coastguard Worker }
3119*38e8c45fSAndroid Build Coastguard Worker
overrideHdrTypes(const sp<IBinder> & display,const std::vector<ui::Hdr> & hdrTypes)3120*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::overrideHdrTypes(const sp<IBinder>& display,
3121*38e8c45fSAndroid Build Coastguard Worker const std::vector<ui::Hdr>& hdrTypes) {
3122*38e8c45fSAndroid Build Coastguard Worker std::vector<int32_t> hdrTypesVector;
3123*38e8c45fSAndroid Build Coastguard Worker hdrTypesVector.reserve(hdrTypes.size());
3124*38e8c45fSAndroid Build Coastguard Worker for (auto t : hdrTypes) {
3125*38e8c45fSAndroid Build Coastguard Worker hdrTypesVector.push_back(static_cast<int32_t>(t));
3126*38e8c45fSAndroid Build Coastguard Worker }
3127*38e8c45fSAndroid Build Coastguard Worker
3128*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3129*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->overrideHdrTypes(display, hdrTypesVector);
3130*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3131*38e8c45fSAndroid Build Coastguard Worker }
3132*38e8c45fSAndroid Build Coastguard Worker
onPullAtom(const int32_t atomId,std::string * outData,bool * success)3133*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::onPullAtom(const int32_t atomId, std::string* outData,
3134*38e8c45fSAndroid Build Coastguard Worker bool* success) {
3135*38e8c45fSAndroid Build Coastguard Worker gui::PullAtomData pad;
3136*38e8c45fSAndroid Build Coastguard Worker binder::Status status = ComposerServiceAIDL::getComposerService()->onPullAtom(atomId, &pad);
3137*38e8c45fSAndroid Build Coastguard Worker if (status.isOk()) {
3138*38e8c45fSAndroid Build Coastguard Worker outData->assign(pad.data.begin(), pad.data.end());
3139*38e8c45fSAndroid Build Coastguard Worker *success = pad.success;
3140*38e8c45fSAndroid Build Coastguard Worker }
3141*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3142*38e8c45fSAndroid Build Coastguard Worker }
3143*38e8c45fSAndroid Build Coastguard Worker
getDisplayedContentSamplingAttributes(const sp<IBinder> & display,ui::PixelFormat * outFormat,ui::Dataspace * outDataspace,uint8_t * outComponentMask)3144*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
3145*38e8c45fSAndroid Build Coastguard Worker ui::PixelFormat* outFormat,
3146*38e8c45fSAndroid Build Coastguard Worker ui::Dataspace* outDataspace,
3147*38e8c45fSAndroid Build Coastguard Worker uint8_t* outComponentMask) {
3148*38e8c45fSAndroid Build Coastguard Worker if (!outFormat || !outDataspace || !outComponentMask) {
3149*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
3150*38e8c45fSAndroid Build Coastguard Worker }
3151*38e8c45fSAndroid Build Coastguard Worker
3152*38e8c45fSAndroid Build Coastguard Worker gui::ContentSamplingAttributes attrs;
3153*38e8c45fSAndroid Build Coastguard Worker binder::Status status = ComposerServiceAIDL::getComposerService()
3154*38e8c45fSAndroid Build Coastguard Worker ->getDisplayedContentSamplingAttributes(display, &attrs);
3155*38e8c45fSAndroid Build Coastguard Worker if (status.isOk()) {
3156*38e8c45fSAndroid Build Coastguard Worker *outFormat = static_cast<ui::PixelFormat>(attrs.format);
3157*38e8c45fSAndroid Build Coastguard Worker *outDataspace = static_cast<ui::Dataspace>(attrs.dataspace);
3158*38e8c45fSAndroid Build Coastguard Worker *outComponentMask = static_cast<uint8_t>(attrs.componentMask);
3159*38e8c45fSAndroid Build Coastguard Worker }
3160*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3161*38e8c45fSAndroid Build Coastguard Worker }
3162*38e8c45fSAndroid Build Coastguard Worker
setDisplayContentSamplingEnabled(const sp<IBinder> & display,bool enable,uint8_t componentMask,uint64_t maxFrames)3163*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::setDisplayContentSamplingEnabled(const sp<IBinder>& display,
3164*38e8c45fSAndroid Build Coastguard Worker bool enable, uint8_t componentMask,
3165*38e8c45fSAndroid Build Coastguard Worker uint64_t maxFrames) {
3166*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3167*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()
3168*38e8c45fSAndroid Build Coastguard Worker ->setDisplayContentSamplingEnabled(display, enable,
3169*38e8c45fSAndroid Build Coastguard Worker static_cast<int8_t>(componentMask),
3170*38e8c45fSAndroid Build Coastguard Worker static_cast<int64_t>(maxFrames));
3171*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3172*38e8c45fSAndroid Build Coastguard Worker }
3173*38e8c45fSAndroid Build Coastguard Worker
getDisplayedContentSample(const sp<IBinder> & display,uint64_t maxFrames,uint64_t timestamp,DisplayedFrameStats * outStats)3174*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::getDisplayedContentSample(const sp<IBinder>& display,
3175*38e8c45fSAndroid Build Coastguard Worker uint64_t maxFrames, uint64_t timestamp,
3176*38e8c45fSAndroid Build Coastguard Worker DisplayedFrameStats* outStats) {
3177*38e8c45fSAndroid Build Coastguard Worker if (!outStats) {
3178*38e8c45fSAndroid Build Coastguard Worker return BAD_VALUE;
3179*38e8c45fSAndroid Build Coastguard Worker }
3180*38e8c45fSAndroid Build Coastguard Worker
3181*38e8c45fSAndroid Build Coastguard Worker gui::DisplayedFrameStats stats;
3182*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3183*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getDisplayedContentSample(display, maxFrames,
3184*38e8c45fSAndroid Build Coastguard Worker timestamp, &stats);
3185*38e8c45fSAndroid Build Coastguard Worker if (status.isOk()) {
3186*38e8c45fSAndroid Build Coastguard Worker // convert gui::DisplayedFrameStats to ui::DisplayedFrameStats
3187*38e8c45fSAndroid Build Coastguard Worker outStats->numFrames = static_cast<uint64_t>(stats.numFrames);
3188*38e8c45fSAndroid Build Coastguard Worker outStats->component_0_sample.reserve(stats.component_0_sample.size());
3189*38e8c45fSAndroid Build Coastguard Worker for (const auto& s : stats.component_0_sample) {
3190*38e8c45fSAndroid Build Coastguard Worker outStats->component_0_sample.push_back(static_cast<uint64_t>(s));
3191*38e8c45fSAndroid Build Coastguard Worker }
3192*38e8c45fSAndroid Build Coastguard Worker outStats->component_1_sample.reserve(stats.component_1_sample.size());
3193*38e8c45fSAndroid Build Coastguard Worker for (const auto& s : stats.component_1_sample) {
3194*38e8c45fSAndroid Build Coastguard Worker outStats->component_1_sample.push_back(static_cast<uint64_t>(s));
3195*38e8c45fSAndroid Build Coastguard Worker }
3196*38e8c45fSAndroid Build Coastguard Worker outStats->component_2_sample.reserve(stats.component_2_sample.size());
3197*38e8c45fSAndroid Build Coastguard Worker for (const auto& s : stats.component_2_sample) {
3198*38e8c45fSAndroid Build Coastguard Worker outStats->component_2_sample.push_back(static_cast<uint64_t>(s));
3199*38e8c45fSAndroid Build Coastguard Worker }
3200*38e8c45fSAndroid Build Coastguard Worker outStats->component_3_sample.reserve(stats.component_3_sample.size());
3201*38e8c45fSAndroid Build Coastguard Worker for (const auto& s : stats.component_3_sample) {
3202*38e8c45fSAndroid Build Coastguard Worker outStats->component_3_sample.push_back(static_cast<uint64_t>(s));
3203*38e8c45fSAndroid Build Coastguard Worker }
3204*38e8c45fSAndroid Build Coastguard Worker }
3205*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3206*38e8c45fSAndroid Build Coastguard Worker }
3207*38e8c45fSAndroid Build Coastguard Worker
isWideColorDisplay(const sp<IBinder> & display,bool * outIsWideColorDisplay)3208*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::isWideColorDisplay(const sp<IBinder>& display,
3209*38e8c45fSAndroid Build Coastguard Worker bool* outIsWideColorDisplay) {
3210*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3211*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->isWideColorDisplay(display,
3212*38e8c45fSAndroid Build Coastguard Worker outIsWideColorDisplay);
3213*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3214*38e8c45fSAndroid Build Coastguard Worker }
3215*38e8c45fSAndroid Build Coastguard Worker
addRegionSamplingListener(const Rect & samplingArea,const sp<IBinder> & stopLayerHandle,const sp<IRegionSamplingListener> & listener)3216*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::addRegionSamplingListener(
3217*38e8c45fSAndroid Build Coastguard Worker const Rect& samplingArea, const sp<IBinder>& stopLayerHandle,
3218*38e8c45fSAndroid Build Coastguard Worker const sp<IRegionSamplingListener>& listener) {
3219*38e8c45fSAndroid Build Coastguard Worker gui::ARect rect;
3220*38e8c45fSAndroid Build Coastguard Worker rect.left = samplingArea.left;
3221*38e8c45fSAndroid Build Coastguard Worker rect.top = samplingArea.top;
3222*38e8c45fSAndroid Build Coastguard Worker rect.right = samplingArea.right;
3223*38e8c45fSAndroid Build Coastguard Worker rect.bottom = samplingArea.bottom;
3224*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3225*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->addRegionSamplingListener(rect,
3226*38e8c45fSAndroid Build Coastguard Worker stopLayerHandle,
3227*38e8c45fSAndroid Build Coastguard Worker listener);
3228*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3229*38e8c45fSAndroid Build Coastguard Worker }
3230*38e8c45fSAndroid Build Coastguard Worker
removeRegionSamplingListener(const sp<IRegionSamplingListener> & listener)3231*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::removeRegionSamplingListener(
3232*38e8c45fSAndroid Build Coastguard Worker const sp<IRegionSamplingListener>& listener) {
3233*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3234*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->removeRegionSamplingListener(listener);
3235*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3236*38e8c45fSAndroid Build Coastguard Worker }
3237*38e8c45fSAndroid Build Coastguard Worker
addFpsListener(int32_t taskId,const sp<gui::IFpsListener> & listener)3238*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::addFpsListener(int32_t taskId,
3239*38e8c45fSAndroid Build Coastguard Worker const sp<gui::IFpsListener>& listener) {
3240*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3241*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->addFpsListener(taskId, listener);
3242*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3243*38e8c45fSAndroid Build Coastguard Worker }
3244*38e8c45fSAndroid Build Coastguard Worker
removeFpsListener(const sp<gui::IFpsListener> & listener)3245*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::removeFpsListener(const sp<gui::IFpsListener>& listener) {
3246*38e8c45fSAndroid Build Coastguard Worker binder::Status status = ComposerServiceAIDL::getComposerService()->removeFpsListener(listener);
3247*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3248*38e8c45fSAndroid Build Coastguard Worker }
3249*38e8c45fSAndroid Build Coastguard Worker
addTunnelModeEnabledListener(const sp<gui::ITunnelModeEnabledListener> & listener)3250*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::addTunnelModeEnabledListener(
3251*38e8c45fSAndroid Build Coastguard Worker const sp<gui::ITunnelModeEnabledListener>& listener) {
3252*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3253*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->addTunnelModeEnabledListener(listener);
3254*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3255*38e8c45fSAndroid Build Coastguard Worker }
3256*38e8c45fSAndroid Build Coastguard Worker
removeTunnelModeEnabledListener(const sp<gui::ITunnelModeEnabledListener> & listener)3257*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::removeTunnelModeEnabledListener(
3258*38e8c45fSAndroid Build Coastguard Worker const sp<gui::ITunnelModeEnabledListener>& listener) {
3259*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3260*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->removeTunnelModeEnabledListener(listener);
3261*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3262*38e8c45fSAndroid Build Coastguard Worker }
3263*38e8c45fSAndroid Build Coastguard Worker
getDisplayBrightnessSupport(const sp<IBinder> & displayToken)3264*38e8c45fSAndroid Build Coastguard Worker bool SurfaceComposerClient::getDisplayBrightnessSupport(const sp<IBinder>& displayToken) {
3265*38e8c45fSAndroid Build Coastguard Worker bool support = false;
3266*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3267*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getDisplayBrightnessSupport(displayToken,
3268*38e8c45fSAndroid Build Coastguard Worker &support);
3269*38e8c45fSAndroid Build Coastguard Worker return status.isOk() ? support : false;
3270*38e8c45fSAndroid Build Coastguard Worker }
3271*38e8c45fSAndroid Build Coastguard Worker
setDisplayBrightness(const sp<IBinder> & displayToken,const gui::DisplayBrightness & brightness)3272*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::setDisplayBrightness(const sp<IBinder>& displayToken,
3273*38e8c45fSAndroid Build Coastguard Worker const gui::DisplayBrightness& brightness) {
3274*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3275*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->setDisplayBrightness(displayToken,
3276*38e8c45fSAndroid Build Coastguard Worker brightness);
3277*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3278*38e8c45fSAndroid Build Coastguard Worker }
3279*38e8c45fSAndroid Build Coastguard Worker
addHdrLayerInfoListener(const sp<IBinder> & displayToken,const sp<gui::IHdrLayerInfoListener> & listener)3280*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::addHdrLayerInfoListener(
3281*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) {
3282*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3283*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->addHdrLayerInfoListener(displayToken,
3284*38e8c45fSAndroid Build Coastguard Worker listener);
3285*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3286*38e8c45fSAndroid Build Coastguard Worker }
3287*38e8c45fSAndroid Build Coastguard Worker
removeHdrLayerInfoListener(const sp<IBinder> & displayToken,const sp<gui::IHdrLayerInfoListener> & listener)3288*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::removeHdrLayerInfoListener(
3289*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& displayToken, const sp<gui::IHdrLayerInfoListener>& listener) {
3290*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3291*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->removeHdrLayerInfoListener(displayToken,
3292*38e8c45fSAndroid Build Coastguard Worker listener);
3293*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3294*38e8c45fSAndroid Build Coastguard Worker }
3295*38e8c45fSAndroid Build Coastguard Worker
setActivePictureListener(const sp<gui::IActivePictureListener> & listener)3296*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::setActivePictureListener(
3297*38e8c45fSAndroid Build Coastguard Worker const sp<gui::IActivePictureListener>& listener) {
3298*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3299*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->setActivePictureListener(listener);
3300*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3301*38e8c45fSAndroid Build Coastguard Worker }
3302*38e8c45fSAndroid Build Coastguard Worker
notifyPowerBoost(int32_t boostId)3303*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::notifyPowerBoost(int32_t boostId) {
3304*38e8c45fSAndroid Build Coastguard Worker binder::Status status = ComposerServiceAIDL::getComposerService()->notifyPowerBoost(boostId);
3305*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3306*38e8c45fSAndroid Build Coastguard Worker }
3307*38e8c45fSAndroid Build Coastguard Worker
setGlobalShadowSettings(const half4 & ambientColor,const half4 & spotColor,float lightPosY,float lightPosZ,float lightRadius)3308*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::setGlobalShadowSettings(const half4& ambientColor,
3309*38e8c45fSAndroid Build Coastguard Worker const half4& spotColor, float lightPosY,
3310*38e8c45fSAndroid Build Coastguard Worker float lightPosZ, float lightRadius) {
3311*38e8c45fSAndroid Build Coastguard Worker gui::Color ambientColorG, spotColorG;
3312*38e8c45fSAndroid Build Coastguard Worker ambientColorG.r = ambientColor.r;
3313*38e8c45fSAndroid Build Coastguard Worker ambientColorG.g = ambientColor.g;
3314*38e8c45fSAndroid Build Coastguard Worker ambientColorG.b = ambientColor.b;
3315*38e8c45fSAndroid Build Coastguard Worker ambientColorG.a = ambientColor.a;
3316*38e8c45fSAndroid Build Coastguard Worker spotColorG.r = spotColor.r;
3317*38e8c45fSAndroid Build Coastguard Worker spotColorG.g = spotColor.g;
3318*38e8c45fSAndroid Build Coastguard Worker spotColorG.b = spotColor.b;
3319*38e8c45fSAndroid Build Coastguard Worker spotColorG.a = spotColor.a;
3320*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3321*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->setGlobalShadowSettings(ambientColorG,
3322*38e8c45fSAndroid Build Coastguard Worker spotColorG,
3323*38e8c45fSAndroid Build Coastguard Worker lightPosY, lightPosZ,
3324*38e8c45fSAndroid Build Coastguard Worker lightRadius);
3325*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3326*38e8c45fSAndroid Build Coastguard Worker }
3327*38e8c45fSAndroid Build Coastguard Worker
getDisplayDecorationSupport(const sp<IBinder> & displayToken)3328*38e8c45fSAndroid Build Coastguard Worker std::optional<DisplayDecorationSupport> SurfaceComposerClient::getDisplayDecorationSupport(
3329*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& displayToken) {
3330*38e8c45fSAndroid Build Coastguard Worker std::optional<gui::DisplayDecorationSupport> gsupport;
3331*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3332*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getDisplayDecorationSupport(displayToken,
3333*38e8c45fSAndroid Build Coastguard Worker &gsupport);
3334*38e8c45fSAndroid Build Coastguard Worker std::optional<DisplayDecorationSupport> support;
3335*38e8c45fSAndroid Build Coastguard Worker if (status.isOk() && gsupport.has_value()) {
3336*38e8c45fSAndroid Build Coastguard Worker support.emplace(DisplayDecorationSupport{
3337*38e8c45fSAndroid Build Coastguard Worker .format =
3338*38e8c45fSAndroid Build Coastguard Worker static_cast<aidl::android::hardware::graphics::common::PixelFormat>(
3339*38e8c45fSAndroid Build Coastguard Worker gsupport->format),
3340*38e8c45fSAndroid Build Coastguard Worker .alphaInterpretation =
3341*38e8c45fSAndroid Build Coastguard Worker static_cast<aidl::android::hardware::graphics::common::AlphaInterpretation>(
3342*38e8c45fSAndroid Build Coastguard Worker gsupport->alphaInterpretation)
3343*38e8c45fSAndroid Build Coastguard Worker });
3344*38e8c45fSAndroid Build Coastguard Worker }
3345*38e8c45fSAndroid Build Coastguard Worker return support;
3346*38e8c45fSAndroid Build Coastguard Worker }
3347*38e8c45fSAndroid Build Coastguard Worker
getGpuContextPriority()3348*38e8c45fSAndroid Build Coastguard Worker int SurfaceComposerClient::getGpuContextPriority() {
3349*38e8c45fSAndroid Build Coastguard Worker int priority;
3350*38e8c45fSAndroid Build Coastguard Worker binder::Status status =
3351*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->getGpuContextPriority(&priority);
3352*38e8c45fSAndroid Build Coastguard Worker if (!status.isOk()) {
3353*38e8c45fSAndroid Build Coastguard Worker status_t err = statusTFromBinderStatus(status);
3354*38e8c45fSAndroid Build Coastguard Worker ALOGE("getGpuContextPriority failed to read data: %s (%d)", strerror(-err), err);
3355*38e8c45fSAndroid Build Coastguard Worker return 0;
3356*38e8c45fSAndroid Build Coastguard Worker }
3357*38e8c45fSAndroid Build Coastguard Worker return priority;
3358*38e8c45fSAndroid Build Coastguard Worker }
3359*38e8c45fSAndroid Build Coastguard Worker
addWindowInfosListener(const sp<WindowInfosListener> & windowInfosListener,std::pair<std::vector<gui::WindowInfo>,std::vector<gui::DisplayInfo>> * outInitialInfo)3360*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::addWindowInfosListener(
3361*38e8c45fSAndroid Build Coastguard Worker const sp<WindowInfosListener>& windowInfosListener,
3362*38e8c45fSAndroid Build Coastguard Worker std::pair<std::vector<gui::WindowInfo>, std::vector<gui::DisplayInfo>>* outInitialInfo) {
3363*38e8c45fSAndroid Build Coastguard Worker return WindowInfosListenerReporter::getInstance()
3364*38e8c45fSAndroid Build Coastguard Worker ->addWindowInfosListener(windowInfosListener, ComposerServiceAIDL::getComposerService(),
3365*38e8c45fSAndroid Build Coastguard Worker outInitialInfo);
3366*38e8c45fSAndroid Build Coastguard Worker }
3367*38e8c45fSAndroid Build Coastguard Worker
removeWindowInfosListener(const sp<WindowInfosListener> & windowInfosListener)3368*38e8c45fSAndroid Build Coastguard Worker status_t SurfaceComposerClient::removeWindowInfosListener(
3369*38e8c45fSAndroid Build Coastguard Worker const sp<WindowInfosListener>& windowInfosListener) {
3370*38e8c45fSAndroid Build Coastguard Worker return WindowInfosListenerReporter::getInstance()
3371*38e8c45fSAndroid Build Coastguard Worker ->removeWindowInfosListener(windowInfosListener,
3372*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService());
3373*38e8c45fSAndroid Build Coastguard Worker }
3374*38e8c45fSAndroid Build Coastguard Worker
notifyShutdown()3375*38e8c45fSAndroid Build Coastguard Worker void SurfaceComposerClient::notifyShutdown() {
3376*38e8c45fSAndroid Build Coastguard Worker ComposerServiceAIDL::getComposerService()->notifyShutdown();
3377*38e8c45fSAndroid Build Coastguard Worker }
3378*38e8c45fSAndroid Build Coastguard Worker // ----------------------------------------------------------------------------
3379*38e8c45fSAndroid Build Coastguard Worker
captureDisplay(const DisplayCaptureArgs & captureArgs,const sp<IScreenCaptureListener> & captureListener)3380*38e8c45fSAndroid Build Coastguard Worker status_t ScreenshotClient::captureDisplay(const DisplayCaptureArgs& captureArgs,
3381*38e8c45fSAndroid Build Coastguard Worker const sp<IScreenCaptureListener>& captureListener) {
3382*38e8c45fSAndroid Build Coastguard Worker sp<gui::ISurfaceComposer> s(ComposerServiceAIDL::getComposerService());
3383*38e8c45fSAndroid Build Coastguard Worker if (s == nullptr) return NO_INIT;
3384*38e8c45fSAndroid Build Coastguard Worker
3385*38e8c45fSAndroid Build Coastguard Worker binder::Status status = s->captureDisplay(captureArgs, captureListener);
3386*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3387*38e8c45fSAndroid Build Coastguard Worker }
3388*38e8c45fSAndroid Build Coastguard Worker
captureDisplay(DisplayId displayId,const gui::CaptureArgs & captureArgs,const sp<IScreenCaptureListener> & captureListener)3389*38e8c45fSAndroid Build Coastguard Worker status_t ScreenshotClient::captureDisplay(DisplayId displayId, const gui::CaptureArgs& captureArgs,
3390*38e8c45fSAndroid Build Coastguard Worker const sp<IScreenCaptureListener>& captureListener) {
3391*38e8c45fSAndroid Build Coastguard Worker sp<gui::ISurfaceComposer> s(ComposerServiceAIDL::getComposerService());
3392*38e8c45fSAndroid Build Coastguard Worker if (s == nullptr) return NO_INIT;
3393*38e8c45fSAndroid Build Coastguard Worker
3394*38e8c45fSAndroid Build Coastguard Worker binder::Status status = s->captureDisplayById(displayId.value, captureArgs, captureListener);
3395*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3396*38e8c45fSAndroid Build Coastguard Worker }
3397*38e8c45fSAndroid Build Coastguard Worker
captureLayers(const LayerCaptureArgs & captureArgs,const sp<IScreenCaptureListener> & captureListener,bool sync)3398*38e8c45fSAndroid Build Coastguard Worker status_t ScreenshotClient::captureLayers(const LayerCaptureArgs& captureArgs,
3399*38e8c45fSAndroid Build Coastguard Worker const sp<IScreenCaptureListener>& captureListener,
3400*38e8c45fSAndroid Build Coastguard Worker bool sync) {
3401*38e8c45fSAndroid Build Coastguard Worker sp<gui::ISurfaceComposer> s(ComposerServiceAIDL::getComposerService());
3402*38e8c45fSAndroid Build Coastguard Worker if (s == nullptr) return NO_INIT;
3403*38e8c45fSAndroid Build Coastguard Worker
3404*38e8c45fSAndroid Build Coastguard Worker binder::Status status;
3405*38e8c45fSAndroid Build Coastguard Worker if (sync) {
3406*38e8c45fSAndroid Build Coastguard Worker gui::ScreenCaptureResults captureResults;
3407*38e8c45fSAndroid Build Coastguard Worker status = s->captureLayersSync(captureArgs, &captureResults);
3408*38e8c45fSAndroid Build Coastguard Worker captureListener->onScreenCaptureCompleted(captureResults);
3409*38e8c45fSAndroid Build Coastguard Worker } else {
3410*38e8c45fSAndroid Build Coastguard Worker status = s->captureLayers(captureArgs, captureListener);
3411*38e8c45fSAndroid Build Coastguard Worker }
3412*38e8c45fSAndroid Build Coastguard Worker return statusTFromBinderStatus(status);
3413*38e8c45fSAndroid Build Coastguard Worker }
3414*38e8c45fSAndroid Build Coastguard Worker
3415*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------------
3416*38e8c45fSAndroid Build Coastguard Worker
addReleaseCallback(const ReleaseCallbackId callbackId,sp<Fence> releaseFence)3417*38e8c45fSAndroid Build Coastguard Worker void ReleaseCallbackThread::addReleaseCallback(const ReleaseCallbackId callbackId,
3418*38e8c45fSAndroid Build Coastguard Worker sp<Fence> releaseFence) {
3419*38e8c45fSAndroid Build Coastguard Worker std::scoped_lock<std::mutex> lock(mMutex);
3420*38e8c45fSAndroid Build Coastguard Worker if (!mStarted) {
3421*38e8c45fSAndroid Build Coastguard Worker mThread = std::thread(&ReleaseCallbackThread::threadMain, this);
3422*38e8c45fSAndroid Build Coastguard Worker mStarted = true;
3423*38e8c45fSAndroid Build Coastguard Worker }
3424*38e8c45fSAndroid Build Coastguard Worker
3425*38e8c45fSAndroid Build Coastguard Worker mCallbackInfos.emplace(callbackId, std::move(releaseFence));
3426*38e8c45fSAndroid Build Coastguard Worker mReleaseCallbackPending.notify_one();
3427*38e8c45fSAndroid Build Coastguard Worker }
3428*38e8c45fSAndroid Build Coastguard Worker
threadMain()3429*38e8c45fSAndroid Build Coastguard Worker void ReleaseCallbackThread::threadMain() {
3430*38e8c45fSAndroid Build Coastguard Worker const auto listener = TransactionCompletedListener::getInstance();
3431*38e8c45fSAndroid Build Coastguard Worker std::queue<std::tuple<const ReleaseCallbackId, const sp<Fence>>> callbackInfos;
3432*38e8c45fSAndroid Build Coastguard Worker while (true) {
3433*38e8c45fSAndroid Build Coastguard Worker {
3434*38e8c45fSAndroid Build Coastguard Worker std::unique_lock<std::mutex> lock(mMutex);
3435*38e8c45fSAndroid Build Coastguard Worker base::ScopedLockAssertion assumeLocked(mMutex);
3436*38e8c45fSAndroid Build Coastguard Worker callbackInfos = std::move(mCallbackInfos);
3437*38e8c45fSAndroid Build Coastguard Worker mCallbackInfos = {};
3438*38e8c45fSAndroid Build Coastguard Worker }
3439*38e8c45fSAndroid Build Coastguard Worker
3440*38e8c45fSAndroid Build Coastguard Worker while (!callbackInfos.empty()) {
3441*38e8c45fSAndroid Build Coastguard Worker auto [callbackId, releaseFence] = callbackInfos.front();
3442*38e8c45fSAndroid Build Coastguard Worker listener->onReleaseBuffer(callbackId, std::move(releaseFence), UINT_MAX);
3443*38e8c45fSAndroid Build Coastguard Worker callbackInfos.pop();
3444*38e8c45fSAndroid Build Coastguard Worker }
3445*38e8c45fSAndroid Build Coastguard Worker
3446*38e8c45fSAndroid Build Coastguard Worker {
3447*38e8c45fSAndroid Build Coastguard Worker std::unique_lock<std::mutex> lock(mMutex);
3448*38e8c45fSAndroid Build Coastguard Worker base::ScopedLockAssertion assumeLocked(mMutex);
3449*38e8c45fSAndroid Build Coastguard Worker if (mCallbackInfos.size() == 0) {
3450*38e8c45fSAndroid Build Coastguard Worker mReleaseCallbackPending.wait(lock);
3451*38e8c45fSAndroid Build Coastguard Worker }
3452*38e8c45fSAndroid Build Coastguard Worker }
3453*38e8c45fSAndroid Build Coastguard Worker }
3454*38e8c45fSAndroid Build Coastguard Worker }
3455*38e8c45fSAndroid Build Coastguard Worker
3456*38e8c45fSAndroid Build Coastguard Worker } // namespace android
3457