xref: /aosp_15_r20/external/drm_hwcomposer/drm/DrmAtomicStateManager.cpp (revision 0a9764fe0a15e71ebbeb85e87e10990c23aab47f)
1*0a9764feSAndroid Build Coastguard Worker /*
2*0a9764feSAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
3*0a9764feSAndroid Build Coastguard Worker  *
4*0a9764feSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*0a9764feSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*0a9764feSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*0a9764feSAndroid Build Coastguard Worker  *
8*0a9764feSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*0a9764feSAndroid Build Coastguard Worker  *
10*0a9764feSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*0a9764feSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*0a9764feSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*0a9764feSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*0a9764feSAndroid Build Coastguard Worker  * limitations under the License.
15*0a9764feSAndroid Build Coastguard Worker  */
16*0a9764feSAndroid Build Coastguard Worker 
17*0a9764feSAndroid Build Coastguard Worker #undef NDEBUG /* Required for assert to work */
18*0a9764feSAndroid Build Coastguard Worker 
19*0a9764feSAndroid Build Coastguard Worker #define ATRACE_TAG ATRACE_TAG_GRAPHICS
20*0a9764feSAndroid Build Coastguard Worker #define LOG_TAG "drmhwc"
21*0a9764feSAndroid Build Coastguard Worker 
22*0a9764feSAndroid Build Coastguard Worker #include "DrmAtomicStateManager.h"
23*0a9764feSAndroid Build Coastguard Worker 
24*0a9764feSAndroid Build Coastguard Worker #include <drm/drm_mode.h>
25*0a9764feSAndroid Build Coastguard Worker #include <sync/sync.h>
26*0a9764feSAndroid Build Coastguard Worker #include <utils/Trace.h>
27*0a9764feSAndroid Build Coastguard Worker 
28*0a9764feSAndroid Build Coastguard Worker #include <cassert>
29*0a9764feSAndroid Build Coastguard Worker 
30*0a9764feSAndroid Build Coastguard Worker #include "drm/DrmCrtc.h"
31*0a9764feSAndroid Build Coastguard Worker #include "drm/DrmDevice.h"
32*0a9764feSAndroid Build Coastguard Worker #include "drm/DrmPlane.h"
33*0a9764feSAndroid Build Coastguard Worker #include "drm/DrmUnique.h"
34*0a9764feSAndroid Build Coastguard Worker #include "utils/log.h"
35*0a9764feSAndroid Build Coastguard Worker 
36*0a9764feSAndroid Build Coastguard Worker namespace android {
37*0a9764feSAndroid Build Coastguard Worker 
CreateInstance(DrmDisplayPipeline * pipe)38*0a9764feSAndroid Build Coastguard Worker auto DrmAtomicStateManager::CreateInstance(DrmDisplayPipeline *pipe)
39*0a9764feSAndroid Build Coastguard Worker     -> std::shared_ptr<DrmAtomicStateManager> {
40*0a9764feSAndroid Build Coastguard Worker   auto dasm = std::shared_ptr<DrmAtomicStateManager>(
41*0a9764feSAndroid Build Coastguard Worker       new DrmAtomicStateManager());
42*0a9764feSAndroid Build Coastguard Worker 
43*0a9764feSAndroid Build Coastguard Worker   dasm->pipe_ = pipe;
44*0a9764feSAndroid Build Coastguard Worker   std::thread(&DrmAtomicStateManager::ThreadFn, dasm.get(), dasm).detach();
45*0a9764feSAndroid Build Coastguard Worker 
46*0a9764feSAndroid Build Coastguard Worker   return dasm;
47*0a9764feSAndroid Build Coastguard Worker }
48*0a9764feSAndroid Build Coastguard Worker 
49*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE (readability-function-cognitive-complexity): Fixme
CommitFrame(AtomicCommitArgs & args)50*0a9764feSAndroid Build Coastguard Worker auto DrmAtomicStateManager::CommitFrame(AtomicCommitArgs &args) -> int {
51*0a9764feSAndroid Build Coastguard Worker   // NOLINTNEXTLINE(misc-const-correctness)
52*0a9764feSAndroid Build Coastguard Worker   ATRACE_CALL();
53*0a9764feSAndroid Build Coastguard Worker 
54*0a9764feSAndroid Build Coastguard Worker   if (args.active && *args.active == active_frame_state_.crtc_active_state) {
55*0a9764feSAndroid Build Coastguard Worker     /* Don't set the same state twice */
56*0a9764feSAndroid Build Coastguard Worker     args.active.reset();
57*0a9764feSAndroid Build Coastguard Worker   }
58*0a9764feSAndroid Build Coastguard Worker 
59*0a9764feSAndroid Build Coastguard Worker   if (!args.HasInputs()) {
60*0a9764feSAndroid Build Coastguard Worker     /* nothing to do */
61*0a9764feSAndroid Build Coastguard Worker     return 0;
62*0a9764feSAndroid Build Coastguard Worker   }
63*0a9764feSAndroid Build Coastguard Worker 
64*0a9764feSAndroid Build Coastguard Worker   if (!active_frame_state_.crtc_active_state) {
65*0a9764feSAndroid Build Coastguard Worker     /* Force activate display */
66*0a9764feSAndroid Build Coastguard Worker     args.active = true;
67*0a9764feSAndroid Build Coastguard Worker   }
68*0a9764feSAndroid Build Coastguard Worker 
69*0a9764feSAndroid Build Coastguard Worker   auto new_frame_state = NewFrameState();
70*0a9764feSAndroid Build Coastguard Worker 
71*0a9764feSAndroid Build Coastguard Worker   auto *drm = pipe_->device;
72*0a9764feSAndroid Build Coastguard Worker   auto *connector = pipe_->connector->Get();
73*0a9764feSAndroid Build Coastguard Worker   auto *crtc = pipe_->crtc->Get();
74*0a9764feSAndroid Build Coastguard Worker 
75*0a9764feSAndroid Build Coastguard Worker   auto pset = MakeDrmModeAtomicReqUnique();
76*0a9764feSAndroid Build Coastguard Worker   if (!pset) {
77*0a9764feSAndroid Build Coastguard Worker     ALOGE("Failed to allocate property set");
78*0a9764feSAndroid Build Coastguard Worker     return -ENOMEM;
79*0a9764feSAndroid Build Coastguard Worker   }
80*0a9764feSAndroid Build Coastguard Worker 
81*0a9764feSAndroid Build Coastguard Worker   int out_fence = -1;
82*0a9764feSAndroid Build Coastguard Worker   if (!args.writeback_fb) {
83*0a9764feSAndroid Build Coastguard Worker     if (!crtc->GetOutFencePtrProperty().  //
84*0a9764feSAndroid Build Coastguard Worker          AtomicSet(*pset, uint64_t(&out_fence))) {
85*0a9764feSAndroid Build Coastguard Worker       return -EINVAL;
86*0a9764feSAndroid Build Coastguard Worker     }
87*0a9764feSAndroid Build Coastguard Worker   } else {
88*0a9764feSAndroid Build Coastguard Worker     if (!connector->GetWritebackOutFenceProperty().  //
89*0a9764feSAndroid Build Coastguard Worker          AtomicSet(*pset, uint64_t(&out_fence))) {
90*0a9764feSAndroid Build Coastguard Worker       return -EINVAL;
91*0a9764feSAndroid Build Coastguard Worker     }
92*0a9764feSAndroid Build Coastguard Worker 
93*0a9764feSAndroid Build Coastguard Worker     if (!connector->GetWritebackFbIdProperty().  //
94*0a9764feSAndroid Build Coastguard Worker          AtomicSet(*pset, args.writeback_fb->GetFbId())) {
95*0a9764feSAndroid Build Coastguard Worker       return -EINVAL;
96*0a9764feSAndroid Build Coastguard Worker     }
97*0a9764feSAndroid Build Coastguard Worker 
98*0a9764feSAndroid Build Coastguard Worker     if (args.writeback_release_fence) {
99*0a9764feSAndroid Build Coastguard Worker       sync_wait(*args.writeback_release_fence, -1);
100*0a9764feSAndroid Build Coastguard Worker       args.writeback_release_fence.reset();
101*0a9764feSAndroid Build Coastguard Worker     }
102*0a9764feSAndroid Build Coastguard Worker   }
103*0a9764feSAndroid Build Coastguard Worker 
104*0a9764feSAndroid Build Coastguard Worker   bool nonblock = !args.blocking;
105*0a9764feSAndroid Build Coastguard Worker 
106*0a9764feSAndroid Build Coastguard Worker   if (args.active) {
107*0a9764feSAndroid Build Coastguard Worker     nonblock = false;
108*0a9764feSAndroid Build Coastguard Worker     new_frame_state.crtc_active_state = *args.active;
109*0a9764feSAndroid Build Coastguard Worker     if (!crtc->GetActiveProperty().AtomicSet(*pset, *args.active ? 1 : 0) ||
110*0a9764feSAndroid Build Coastguard Worker         !connector->GetCrtcIdProperty().AtomicSet(*pset, crtc->GetId())) {
111*0a9764feSAndroid Build Coastguard Worker       return -EINVAL;
112*0a9764feSAndroid Build Coastguard Worker     }
113*0a9764feSAndroid Build Coastguard Worker   }
114*0a9764feSAndroid Build Coastguard Worker 
115*0a9764feSAndroid Build Coastguard Worker   if (args.display_mode) {
116*0a9764feSAndroid Build Coastguard Worker     new_frame_state.mode_blob = args.display_mode.value().CreateModeBlob(*drm);
117*0a9764feSAndroid Build Coastguard Worker 
118*0a9764feSAndroid Build Coastguard Worker     if (!new_frame_state.mode_blob) {
119*0a9764feSAndroid Build Coastguard Worker       ALOGE("Failed to create mode_blob");
120*0a9764feSAndroid Build Coastguard Worker       return -EINVAL;
121*0a9764feSAndroid Build Coastguard Worker     }
122*0a9764feSAndroid Build Coastguard Worker 
123*0a9764feSAndroid Build Coastguard Worker     if (!crtc->GetModeProperty().AtomicSet(*pset, *new_frame_state.mode_blob)) {
124*0a9764feSAndroid Build Coastguard Worker       return -EINVAL;
125*0a9764feSAndroid Build Coastguard Worker     }
126*0a9764feSAndroid Build Coastguard Worker   }
127*0a9764feSAndroid Build Coastguard Worker 
128*0a9764feSAndroid Build Coastguard Worker   if (args.color_matrix && crtc->GetCtmProperty()) {
129*0a9764feSAndroid Build Coastguard Worker     auto blob = drm->RegisterUserPropertyBlob(args.color_matrix.get(),
130*0a9764feSAndroid Build Coastguard Worker                                               sizeof(drm_color_ctm));
131*0a9764feSAndroid Build Coastguard Worker     new_frame_state.ctm_blob = std::move(blob);
132*0a9764feSAndroid Build Coastguard Worker 
133*0a9764feSAndroid Build Coastguard Worker     if (!new_frame_state.ctm_blob) {
134*0a9764feSAndroid Build Coastguard Worker       ALOGE("Failed to create CTM blob");
135*0a9764feSAndroid Build Coastguard Worker       return -EINVAL;
136*0a9764feSAndroid Build Coastguard Worker     }
137*0a9764feSAndroid Build Coastguard Worker 
138*0a9764feSAndroid Build Coastguard Worker     if (!crtc->GetCtmProperty().AtomicSet(*pset, *new_frame_state.ctm_blob))
139*0a9764feSAndroid Build Coastguard Worker       return -EINVAL;
140*0a9764feSAndroid Build Coastguard Worker   }
141*0a9764feSAndroid Build Coastguard Worker 
142*0a9764feSAndroid Build Coastguard Worker   if (args.colorspace && connector->GetColorspaceProperty()) {
143*0a9764feSAndroid Build Coastguard Worker     if (!connector->GetColorspaceProperty()
144*0a9764feSAndroid Build Coastguard Worker              .AtomicSet(*pset, connector->GetColorspacePropertyValue(*args.colorspace)))
145*0a9764feSAndroid Build Coastguard Worker       return -EINVAL;
146*0a9764feSAndroid Build Coastguard Worker   }
147*0a9764feSAndroid Build Coastguard Worker 
148*0a9764feSAndroid Build Coastguard Worker   if (args.content_type && connector->GetContentTypeProperty()) {
149*0a9764feSAndroid Build Coastguard Worker     if (!connector->GetContentTypeProperty().AtomicSet(*pset, *args.content_type))
150*0a9764feSAndroid Build Coastguard Worker       return -EINVAL;
151*0a9764feSAndroid Build Coastguard Worker   }
152*0a9764feSAndroid Build Coastguard Worker 
153*0a9764feSAndroid Build Coastguard Worker   auto unused_planes = new_frame_state.used_planes;
154*0a9764feSAndroid Build Coastguard Worker 
155*0a9764feSAndroid Build Coastguard Worker   if (args.composition) {
156*0a9764feSAndroid Build Coastguard Worker     new_frame_state.used_planes.clear();
157*0a9764feSAndroid Build Coastguard Worker 
158*0a9764feSAndroid Build Coastguard Worker     for (auto &joining : args.composition->plan) {
159*0a9764feSAndroid Build Coastguard Worker       DrmPlane *plane = joining.plane->Get();
160*0a9764feSAndroid Build Coastguard Worker       LayerData &layer = joining.layer;
161*0a9764feSAndroid Build Coastguard Worker 
162*0a9764feSAndroid Build Coastguard Worker       new_frame_state.used_framebuffers.emplace_back(layer.fb);
163*0a9764feSAndroid Build Coastguard Worker       new_frame_state.used_planes.emplace_back(joining.plane);
164*0a9764feSAndroid Build Coastguard Worker 
165*0a9764feSAndroid Build Coastguard Worker       /* Remove from 'unused' list, since plane is re-used */
166*0a9764feSAndroid Build Coastguard Worker       auto &v = unused_planes;
167*0a9764feSAndroid Build Coastguard Worker       v.erase(std::remove(v.begin(), v.end(), joining.plane), v.end());
168*0a9764feSAndroid Build Coastguard Worker 
169*0a9764feSAndroid Build Coastguard Worker       if (plane->AtomicSetState(*pset, layer, joining.z_pos, crtc->GetId()) !=
170*0a9764feSAndroid Build Coastguard Worker           0) {
171*0a9764feSAndroid Build Coastguard Worker         return -EINVAL;
172*0a9764feSAndroid Build Coastguard Worker       }
173*0a9764feSAndroid Build Coastguard Worker     }
174*0a9764feSAndroid Build Coastguard Worker   }
175*0a9764feSAndroid Build Coastguard Worker 
176*0a9764feSAndroid Build Coastguard Worker   if (args.composition) {
177*0a9764feSAndroid Build Coastguard Worker     for (auto &plane : unused_planes) {
178*0a9764feSAndroid Build Coastguard Worker       if (plane->Get()->AtomicDisablePlane(*pset) != 0) {
179*0a9764feSAndroid Build Coastguard Worker         return -EINVAL;
180*0a9764feSAndroid Build Coastguard Worker       }
181*0a9764feSAndroid Build Coastguard Worker     }
182*0a9764feSAndroid Build Coastguard Worker   }
183*0a9764feSAndroid Build Coastguard Worker 
184*0a9764feSAndroid Build Coastguard Worker   uint32_t flags = DRM_MODE_ATOMIC_ALLOW_MODESET;
185*0a9764feSAndroid Build Coastguard Worker 
186*0a9764feSAndroid Build Coastguard Worker   if (args.test_only) {
187*0a9764feSAndroid Build Coastguard Worker     return drmModeAtomicCommit(*drm->GetFd(), pset.get(),
188*0a9764feSAndroid Build Coastguard Worker                                flags | DRM_MODE_ATOMIC_TEST_ONLY, drm);
189*0a9764feSAndroid Build Coastguard Worker   }
190*0a9764feSAndroid Build Coastguard Worker 
191*0a9764feSAndroid Build Coastguard Worker   if (last_present_fence_) {
192*0a9764feSAndroid Build Coastguard Worker     // NOLINTNEXTLINE(misc-const-correctness)
193*0a9764feSAndroid Build Coastguard Worker     ATRACE_NAME("WaitPriorFramePresented");
194*0a9764feSAndroid Build Coastguard Worker 
195*0a9764feSAndroid Build Coastguard Worker     constexpr int kTimeoutMs = 500;
196*0a9764feSAndroid Build Coastguard Worker     const int err = sync_wait(*last_present_fence_, kTimeoutMs);
197*0a9764feSAndroid Build Coastguard Worker     if (err != 0) {
198*0a9764feSAndroid Build Coastguard Worker       ALOGE("sync_wait(fd=%i) returned: %i (errno: %i)", *last_present_fence_,
199*0a9764feSAndroid Build Coastguard Worker             err, errno);
200*0a9764feSAndroid Build Coastguard Worker     }
201*0a9764feSAndroid Build Coastguard Worker 
202*0a9764feSAndroid Build Coastguard Worker     CleanupPriorFrameResources();
203*0a9764feSAndroid Build Coastguard Worker   }
204*0a9764feSAndroid Build Coastguard Worker 
205*0a9764feSAndroid Build Coastguard Worker   if (nonblock) {
206*0a9764feSAndroid Build Coastguard Worker     flags |= DRM_MODE_ATOMIC_NONBLOCK;
207*0a9764feSAndroid Build Coastguard Worker   }
208*0a9764feSAndroid Build Coastguard Worker 
209*0a9764feSAndroid Build Coastguard Worker   auto err = drmModeAtomicCommit(*drm->GetFd(), pset.get(), flags, drm);
210*0a9764feSAndroid Build Coastguard Worker 
211*0a9764feSAndroid Build Coastguard Worker   if (err != 0) {
212*0a9764feSAndroid Build Coastguard Worker     ALOGE("Failed to commit pset ret=%d\n", err);
213*0a9764feSAndroid Build Coastguard Worker     return err;
214*0a9764feSAndroid Build Coastguard Worker   }
215*0a9764feSAndroid Build Coastguard Worker 
216*0a9764feSAndroid Build Coastguard Worker   args.out_fence = MakeSharedFd(out_fence);
217*0a9764feSAndroid Build Coastguard Worker 
218*0a9764feSAndroid Build Coastguard Worker   if (nonblock) {
219*0a9764feSAndroid Build Coastguard Worker     {
220*0a9764feSAndroid Build Coastguard Worker       const std::unique_lock lock(mutex_);
221*0a9764feSAndroid Build Coastguard Worker       last_present_fence_ = args.out_fence;
222*0a9764feSAndroid Build Coastguard Worker       staged_frame_state_ = std::move(new_frame_state);
223*0a9764feSAndroid Build Coastguard Worker       frames_staged_++;
224*0a9764feSAndroid Build Coastguard Worker     }
225*0a9764feSAndroid Build Coastguard Worker     cv_.notify_all();
226*0a9764feSAndroid Build Coastguard Worker   } else {
227*0a9764feSAndroid Build Coastguard Worker     active_frame_state_ = std::move(new_frame_state);
228*0a9764feSAndroid Build Coastguard Worker   }
229*0a9764feSAndroid Build Coastguard Worker 
230*0a9764feSAndroid Build Coastguard Worker   return 0;
231*0a9764feSAndroid Build Coastguard Worker }
232*0a9764feSAndroid Build Coastguard Worker 
ThreadFn(const std::shared_ptr<DrmAtomicStateManager> & dasm)233*0a9764feSAndroid Build Coastguard Worker void DrmAtomicStateManager::ThreadFn(
234*0a9764feSAndroid Build Coastguard Worker     const std::shared_ptr<DrmAtomicStateManager> &dasm) {
235*0a9764feSAndroid Build Coastguard Worker   int tracking_at_the_moment = -1;
236*0a9764feSAndroid Build Coastguard Worker   auto &main_mutex = pipe_->device->GetResMan().GetMainLock();
237*0a9764feSAndroid Build Coastguard Worker 
238*0a9764feSAndroid Build Coastguard Worker   for (;;) {
239*0a9764feSAndroid Build Coastguard Worker     SharedFd present_fence;
240*0a9764feSAndroid Build Coastguard Worker 
241*0a9764feSAndroid Build Coastguard Worker     {
242*0a9764feSAndroid Build Coastguard Worker       std::unique_lock lk(mutex_);
243*0a9764feSAndroid Build Coastguard Worker       cv_.wait(lk);
244*0a9764feSAndroid Build Coastguard Worker 
245*0a9764feSAndroid Build Coastguard Worker       if (exit_thread_ || dasm.use_count() == 1)
246*0a9764feSAndroid Build Coastguard Worker         break;
247*0a9764feSAndroid Build Coastguard Worker 
248*0a9764feSAndroid Build Coastguard Worker       if (frames_staged_ <= tracking_at_the_moment)
249*0a9764feSAndroid Build Coastguard Worker         continue;
250*0a9764feSAndroid Build Coastguard Worker 
251*0a9764feSAndroid Build Coastguard Worker       tracking_at_the_moment = frames_staged_;
252*0a9764feSAndroid Build Coastguard Worker 
253*0a9764feSAndroid Build Coastguard Worker       present_fence = last_present_fence_;
254*0a9764feSAndroid Build Coastguard Worker       if (!present_fence)
255*0a9764feSAndroid Build Coastguard Worker         continue;
256*0a9764feSAndroid Build Coastguard Worker     }
257*0a9764feSAndroid Build Coastguard Worker 
258*0a9764feSAndroid Build Coastguard Worker     {
259*0a9764feSAndroid Build Coastguard Worker       // NOLINTNEXTLINE(misc-const-correctness)
260*0a9764feSAndroid Build Coastguard Worker       ATRACE_NAME("AsyncWaitForBuffersSwap");
261*0a9764feSAndroid Build Coastguard Worker       constexpr int kTimeoutMs = 500;
262*0a9764feSAndroid Build Coastguard Worker       auto err = sync_wait(*present_fence, kTimeoutMs);
263*0a9764feSAndroid Build Coastguard Worker       if (err != 0) {
264*0a9764feSAndroid Build Coastguard Worker         ALOGE("sync_wait(fd=%i) returned: %i (errno: %i)", *present_fence, err,
265*0a9764feSAndroid Build Coastguard Worker               errno);
266*0a9764feSAndroid Build Coastguard Worker       }
267*0a9764feSAndroid Build Coastguard Worker     }
268*0a9764feSAndroid Build Coastguard Worker 
269*0a9764feSAndroid Build Coastguard Worker     {
270*0a9764feSAndroid Build Coastguard Worker       const std::unique_lock mlk(main_mutex);
271*0a9764feSAndroid Build Coastguard Worker       const std::unique_lock lk(mutex_);
272*0a9764feSAndroid Build Coastguard Worker       if (exit_thread_)
273*0a9764feSAndroid Build Coastguard Worker         break;
274*0a9764feSAndroid Build Coastguard Worker 
275*0a9764feSAndroid Build Coastguard Worker       /* If resources is already cleaned-up by main thread, skip */
276*0a9764feSAndroid Build Coastguard Worker       if (tracking_at_the_moment > frames_tracked_)
277*0a9764feSAndroid Build Coastguard Worker         CleanupPriorFrameResources();
278*0a9764feSAndroid Build Coastguard Worker     }
279*0a9764feSAndroid Build Coastguard Worker   }
280*0a9764feSAndroid Build Coastguard Worker 
281*0a9764feSAndroid Build Coastguard Worker   ALOGI("DrmAtomicStateManager thread exit");
282*0a9764feSAndroid Build Coastguard Worker }
283*0a9764feSAndroid Build Coastguard Worker 
CleanupPriorFrameResources()284*0a9764feSAndroid Build Coastguard Worker void DrmAtomicStateManager::CleanupPriorFrameResources() {
285*0a9764feSAndroid Build Coastguard Worker   assert(frames_staged_ - frames_tracked_ == 1);
286*0a9764feSAndroid Build Coastguard Worker   assert(last_present_fence_);
287*0a9764feSAndroid Build Coastguard Worker 
288*0a9764feSAndroid Build Coastguard Worker   // NOLINTNEXTLINE(misc-const-correctness)
289*0a9764feSAndroid Build Coastguard Worker   ATRACE_NAME("CleanupPriorFrameResources");
290*0a9764feSAndroid Build Coastguard Worker   frames_tracked_++;
291*0a9764feSAndroid Build Coastguard Worker   active_frame_state_ = std::move(staged_frame_state_);
292*0a9764feSAndroid Build Coastguard Worker   last_present_fence_ = {};
293*0a9764feSAndroid Build Coastguard Worker }
294*0a9764feSAndroid Build Coastguard Worker 
ExecuteAtomicCommit(AtomicCommitArgs & args)295*0a9764feSAndroid Build Coastguard Worker auto DrmAtomicStateManager::ExecuteAtomicCommit(AtomicCommitArgs &args) -> int {
296*0a9764feSAndroid Build Coastguard Worker   auto err = CommitFrame(args);
297*0a9764feSAndroid Build Coastguard Worker 
298*0a9764feSAndroid Build Coastguard Worker   if (!args.test_only) {
299*0a9764feSAndroid Build Coastguard Worker     if (err != 0) {
300*0a9764feSAndroid Build Coastguard Worker       ALOGE("Composite failed for pipeline %s",
301*0a9764feSAndroid Build Coastguard Worker             pipe_->connector->Get()->GetName().c_str());
302*0a9764feSAndroid Build Coastguard Worker       // Disable the hw used by the last active composition. This allows us to
303*0a9764feSAndroid Build Coastguard Worker       // signal the release fences from that composition to avoid hanging.
304*0a9764feSAndroid Build Coastguard Worker       AtomicCommitArgs cl_args{};
305*0a9764feSAndroid Build Coastguard Worker       cl_args.composition = std::make_shared<DrmKmsPlan>();
306*0a9764feSAndroid Build Coastguard Worker       if (CommitFrame(cl_args) != 0) {
307*0a9764feSAndroid Build Coastguard Worker         ALOGE("Failed to clean-up active composition for pipeline %s",
308*0a9764feSAndroid Build Coastguard Worker               pipe_->connector->Get()->GetName().c_str());
309*0a9764feSAndroid Build Coastguard Worker       }
310*0a9764feSAndroid Build Coastguard Worker       return err;
311*0a9764feSAndroid Build Coastguard Worker     }
312*0a9764feSAndroid Build Coastguard Worker   }
313*0a9764feSAndroid Build Coastguard Worker 
314*0a9764feSAndroid Build Coastguard Worker   return err;
315*0a9764feSAndroid Build Coastguard Worker }  // namespace android
316*0a9764feSAndroid Build Coastguard Worker 
ActivateDisplayUsingDPMS()317*0a9764feSAndroid Build Coastguard Worker auto DrmAtomicStateManager::ActivateDisplayUsingDPMS() -> int {
318*0a9764feSAndroid Build Coastguard Worker   return drmModeConnectorSetProperty(*pipe_->device->GetFd(),
319*0a9764feSAndroid Build Coastguard Worker                                      pipe_->connector->Get()->GetId(),
320*0a9764feSAndroid Build Coastguard Worker                                      pipe_->connector->Get()
321*0a9764feSAndroid Build Coastguard Worker                                          ->GetDpmsProperty()
322*0a9764feSAndroid Build Coastguard Worker                                          .GetId(),
323*0a9764feSAndroid Build Coastguard Worker                                      DRM_MODE_DPMS_ON);
324*0a9764feSAndroid Build Coastguard Worker }
325*0a9764feSAndroid Build Coastguard Worker 
326*0a9764feSAndroid Build Coastguard Worker }  // namespace android
327