blob: 5b16cad0fe66a1773bac70192152ef38d9d6eb35 [file] [log] [blame]
Sean Paul98e73c82015-06-24 14:38:49 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18#define LOG_TAG "hwc-drm-display-compositor"
19
Roman Stratiienko13cc3662020-08-29 21:35:39 +030020#include "DrmDisplayCompositor.h"
Zach Reiznerbff33ac2015-11-16 11:08:46 -080021
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030022#include <drm/drm_mode.h>
Zach Reiznerbff33ac2015-11-16 11:08:46 -080023#include <pthread.h>
24#include <sched.h>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030025#include <sync/sync.h>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030026#include <utils/Trace.h>
27
Roman Kovalivskyi9170b312020-02-03 18:13:57 +020028#include <array>
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020029#include <cstdlib>
30#include <ctime>
Zach Reiznerbff33ac2015-11-16 11:08:46 -080031#include <sstream>
32#include <vector>
33
Roman Stratiienko13cc3662020-08-29 21:35:39 +030034#include "drm/DrmCrtc.h"
35#include "drm/DrmDevice.h"
36#include "drm/DrmPlane.h"
Roman Stratiienko3e8ce572021-09-29 12:46:28 +030037#include "drm/DrmUnique.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030038#include "utils/autolock.h"
Roman Stratiienkod21071f2021-03-09 21:56:50 +020039#include "utils/log.h"
Sean Paul98e73c82015-06-24 14:38:49 -070040
Sean Paul98e73c82015-06-24 14:38:49 -070041namespace android {
42
43DrmDisplayCompositor::DrmDisplayCompositor()
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020044 : resource_manager_(nullptr),
Sean Paul98e73c82015-06-24 14:38:49 -070045 display_(-1),
Sean Paul98e73c82015-06-24 14:38:49 -070046 initialized_(false),
Sean Pauldb7a17d2015-06-24 18:46:05 -070047 active_(false),
Sean Paul6c18b3b2015-11-25 11:04:25 -050048 use_hw_overlays_(true),
Sean Paul98e73c82015-06-24 14:38:49 -070049 dump_frames_composited_(0),
Roman Stratiienkoe8c06792021-09-30 10:09:31 +030050 dump_last_timestamp_ns_(0) {
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020051 struct timespec ts {};
Sean Paul98e73c82015-06-24 14:38:49 -070052 if (clock_gettime(CLOCK_MONOTONIC, &ts))
53 return;
54 dump_last_timestamp_ns_ = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
55}
56
57DrmDisplayCompositor::~DrmDisplayCompositor() {
58 if (!initialized_)
59 return;
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +010060 DrmDevice *drm = resource_manager_->GetDrmDevice(display_);
Sean Paul35301f42015-11-17 14:46:56 -050061 if (mode_.blob_id)
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +010062 drm->DestroyPropertyBlob(mode_.blob_id);
Sean Paul35301f42015-11-17 14:46:56 -050063 if (mode_.old_blob_id)
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +010064 drm->DestroyPropertyBlob(mode_.old_blob_id);
Sean Paul35301f42015-11-17 14:46:56 -050065
Sean Paul98e73c82015-06-24 14:38:49 -070066 active_composition_.reset();
Sean Paul98e73c82015-06-24 14:38:49 -070067}
68
Roman Stratiienkoe8c06792021-09-30 10:09:31 +030069auto DrmDisplayCompositor::Init(ResourceManager *resource_manager, int display)
Roman Stratiienko863a3c22021-09-29 13:00:29 +030070 -> int {
Alexandru Gheorghe6f0030f2018-05-01 17:25:48 +010071 resource_manager_ = resource_manager;
Sean Paul98e73c82015-06-24 14:38:49 -070072 display_ = display;
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010073 DrmDevice *drm = resource_manager_->GetDrmDevice(display);
74 if (!drm) {
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +010075 ALOGE("Could not find drmdevice for display");
76 return -EINVAL;
77 }
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010078 planner_ = Planner::CreateInstance(drm);
79
Sean Paul98e73c82015-06-24 14:38:49 -070080 initialized_ = true;
81 return 0;
82}
83
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010084std::unique_ptr<DrmDisplayComposition>
85DrmDisplayCompositor::CreateInitializedComposition() const {
86 DrmDevice *drm = resource_manager_->GetDrmDevice(display_);
87 DrmCrtc *crtc = drm->GetCrtcForDisplay(display_);
88 if (!crtc) {
89 ALOGE("Failed to find crtc for display = %d", display_);
90 return std::unique_ptr<DrmDisplayComposition>();
91 }
Matvii Zorin704ea0e2021-01-08 12:55:45 +020092
93 return std::make_unique<DrmDisplayComposition>(crtc, planner_.get());
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010094}
95
Zach Reizner92f8e632015-10-12 17:47:13 -070096std::tuple<uint32_t, uint32_t, int>
97DrmDisplayCompositor::GetActiveModeResolution() {
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +010098 DrmDevice *drm = resource_manager_->GetDrmDevice(display_);
99 DrmConnector *connector = drm->GetConnectorForDisplay(display_);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200100 if (connector == nullptr) {
Zach Reizner92f8e632015-10-12 17:47:13 -0700101 ALOGE("Failed to determine display mode: no connector for display %d",
102 display_);
103 return std::make_tuple(0, 0, -ENODEV);
104 }
105
106 const DrmMode &mode = connector->active_mode();
107 return std::make_tuple(mode.h_display(), mode.v_display(), 0);
Zach Reizner713a6782015-07-31 15:12:44 -0700108}
109
Sean Paul7b1e4bc2015-10-13 15:47:22 -0400110int DrmDisplayCompositor::DisablePlanes(DrmDisplayComposition *display_comp) {
Roman Stratiienko3e8ce572021-09-29 12:46:28 +0300111 auto pset = MakeDrmModeAtomicReqUnique();
Sean Paul7b1e4bc2015-10-13 15:47:22 -0400112 if (!pset) {
113 ALOGE("Failed to allocate property set");
114 return -ENOMEM;
115 }
116
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +0200117 int ret = 0;
Sean Paulf72cccd2018-08-27 13:59:08 -0400118 std::vector<DrmCompositionPlane> &comp_planes = display_comp
119 ->composition_planes();
Zach Reizner92f8e632015-10-12 17:47:13 -0700120 for (DrmCompositionPlane &comp_plane : comp_planes) {
Roman Stratiienko0dbe6392021-09-29 12:47:16 +0300121 if (comp_plane.plane()->AtomicDisablePlane(*pset) != 0) {
Roman Stratiienko7fd8f882021-09-29 12:46:54 +0300122 return -EINVAL;
Sean Paul7b1e4bc2015-10-13 15:47:22 -0400123 }
124 }
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +0100125 DrmDevice *drm = resource_manager_->GetDrmDevice(display_);
Roman Stratiienko3e8ce572021-09-29 12:46:28 +0300126 ret = drmModeAtomicCommit(drm->fd(), pset.get(), 0, drm);
Sean Paul7b1e4bc2015-10-13 15:47:22 -0400127 if (ret) {
128 ALOGE("Failed to commit pset ret=%d\n", ret);
Sean Paul7b1e4bc2015-10-13 15:47:22 -0400129 return ret;
130 }
131
Sean Paul7b1e4bc2015-10-13 15:47:22 -0400132 return 0;
133}
134
Sean Paulc07b2112015-11-17 16:38:10 -0500135int DrmDisplayCompositor::CommitFrame(DrmDisplayComposition *display_comp,
Roman Stratiienko74774712021-02-05 16:32:47 +0200136 bool test_only) {
Haixia Shi3979f7d2015-10-29 14:33:37 -0700137 ATRACE_CALL();
138
Haixia Shidda2fab2015-10-22 18:12:49 -0700139 int ret = 0;
140
141 std::vector<DrmHwcLayer> &layers = display_comp->layers();
Sean Paulf72cccd2018-08-27 13:59:08 -0400142 std::vector<DrmCompositionPlane> &comp_planes = display_comp
143 ->composition_planes();
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +0100144 DrmDevice *drm = resource_manager_->GetDrmDevice(display_);
145 uint64_t out_fences[drm->crtcs().size()];
Haixia Shidda2fab2015-10-22 18:12:49 -0700146
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +0100147 DrmConnector *connector = drm->GetConnectorForDisplay(display_);
Sean Paul57355412015-09-19 09:14:34 -0400148 if (!connector) {
149 ALOGE("Could not locate connector for display %d", display_);
150 return -ENODEV;
151 }
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +0100152 DrmCrtc *crtc = drm->GetCrtcForDisplay(display_);
Sean Paul57355412015-09-19 09:14:34 -0400153 if (!crtc) {
154 ALOGE("Could not locate crtc for display %d", display_);
155 return -ENODEV;
156 }
157
Roman Stratiienko7fd8f882021-09-29 12:46:54 +0300158 auto pset = MakeDrmModeAtomicReqUnique();
Sean Paul98e73c82015-06-24 14:38:49 -0700159 if (!pset) {
160 ALOGE("Failed to allocate property set");
161 return -ENOMEM;
162 }
163
Roman Stratiienko7fd8f882021-09-29 12:46:54 +0300164 if (crtc->out_fence_ptr_property() &&
165 !crtc->out_fence_ptr_property()
166 .AtomicSet(*pset, (uint64_t)&out_fences[crtc->pipe()])) {
167 return -EINVAL;
Robert Fossa1ade4e2017-09-27 19:28:15 +0200168 }
169
Roman Stratiienko7fd8f882021-09-29 12:46:54 +0300170 if (mode_.needs_modeset &&
171 (!crtc->active_property().AtomicSet(*pset, 1) ||
172 !crtc->mode_property().AtomicSet(*pset, mode_.blob_id) ||
173 !connector->crtc_id_property().AtomicSet(*pset, crtc->id()))) {
174 return -EINVAL;
Sean Paul57355412015-09-19 09:14:34 -0400175 }
176
Zach Reizner92f8e632015-10-12 17:47:13 -0700177 for (DrmCompositionPlane &comp_plane : comp_planes) {
Sean Paulca699be2016-05-11 16:29:45 -0400178 DrmPlane *plane = comp_plane.plane();
Sean Paulca699be2016-05-11 16:29:45 -0400179 std::vector<size_t> &source_layers = comp_plane.source_layers();
Zach Reizner92f8e632015-10-12 17:47:13 -0700180
Sean Paulbbe39db2016-05-11 16:57:26 -0400181 if (comp_plane.type() != DrmCompositionPlane::Type::kDisable) {
Sean Paulca699be2016-05-11 16:29:45 -0400182 if (source_layers.size() > 1) {
183 ALOGE("Can't handle more than one source layer sz=%zu type=%d",
184 source_layers.size(), comp_plane.type());
185 continue;
186 }
187
188 if (source_layers.empty() || source_layers.front() >= layers.size()) {
189 ALOGE("Source layer index %zu out of bounds %zu type=%d",
190 source_layers.front(), layers.size(), comp_plane.type());
Roman Stratiienko0dbe6392021-09-29 12:47:16 +0300191 return -EINVAL;
Sean Paul98e73c82015-06-24 14:38:49 -0700192 }
Sean Paulca699be2016-05-11 16:29:45 -0400193 DrmHwcLayer &layer = layers[source_layers.front()];
Roman Stratiienko0dbe6392021-09-29 12:47:16 +0300194
195 if (plane->AtomicSetState(*pset, layer, source_layers.front(),
196 crtc->id()) != 0) {
197 return -EINVAL;
Sean Paul39b37842016-05-11 13:50:28 -0400198 }
Roman Stratiienko0dbe6392021-09-29 12:47:16 +0300199 } else {
200 if (plane->AtomicDisablePlane(*pset) != 0) {
201 return -EINVAL;
Matvii Zorin8338c342020-09-08 16:12:51 +0300202 }
203 }
Sean Paul98e73c82015-06-24 14:38:49 -0700204 }
205
206 if (!ret) {
Sean Paulc07b2112015-11-17 16:38:10 -0500207 uint32_t flags = DRM_MODE_ATOMIC_ALLOW_MODESET;
208 if (test_only)
209 flags |= DRM_MODE_ATOMIC_TEST_ONLY;
210
Roman Stratiienko7fd8f882021-09-29 12:46:54 +0300211 ret = drmModeAtomicCommit(drm->fd(), pset.get(), flags, drm);
Sean Paul57355412015-09-19 09:14:34 -0400212 if (ret) {
John Stultz78c9f6c2018-05-24 16:43:35 -0700213 if (!test_only)
Sean Paulc07b2112015-11-17 16:38:10 -0500214 ALOGE("Failed to commit pset ret=%d\n", ret);
Sean Paul57355412015-09-19 09:14:34 -0400215 return ret;
216 }
Sean Paul98e73c82015-06-24 14:38:49 -0700217 }
Sean Paul98e73c82015-06-24 14:38:49 -0700218
Sean Paulc07b2112015-11-17 16:38:10 -0500219 if (!test_only && mode_.needs_modeset) {
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +0100220 ret = drm->DestroyPropertyBlob(mode_.old_blob_id);
Sean Paul57355412015-09-19 09:14:34 -0400221 if (ret) {
Sean Paulf741c672016-05-11 13:49:38 -0400222 ALOGE("Failed to destroy old mode property blob %" PRIu32 "/%d",
Sean Paul35301f42015-11-17 14:46:56 -0500223 mode_.old_blob_id, ret);
Sean Paul57355412015-09-19 09:14:34 -0400224 return ret;
225 }
226
227 /* TODO: Add dpms to the pset when the kernel supports it */
228 ret = ApplyDpms(display_comp);
229 if (ret) {
230 ALOGE("Failed to apply DPMS after modeset %d\n", ret);
231 return ret;
232 }
233
Sean Paul35301f42015-11-17 14:46:56 -0500234 connector->set_active_mode(mode_.mode);
235 mode_.old_blob_id = mode_.blob_id;
236 mode_.blob_id = 0;
237 mode_.needs_modeset = false;
Sean Paul57355412015-09-19 09:14:34 -0400238 }
239
Roman Stratiienko7fd8f882021-09-29 12:46:54 +0300240 if (crtc->out_fence_ptr_property()) {
Roman Stratiienko0fade372021-02-20 13:59:55 +0200241 display_comp->out_fence_ = UniqueFd((int)out_fences[crtc->pipe()]);
Robert Fossa1ade4e2017-09-27 19:28:15 +0200242 }
243
Sean Paul98e73c82015-06-24 14:38:49 -0700244 return ret;
245}
246
Sean Pauldb7a17d2015-06-24 18:46:05 -0700247int DrmDisplayCompositor::ApplyDpms(DrmDisplayComposition *display_comp) {
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +0100248 DrmDevice *drm = resource_manager_->GetDrmDevice(display_);
249 DrmConnector *conn = drm->GetConnectorForDisplay(display_);
Sean Pauldb7a17d2015-06-24 18:46:05 -0700250 if (!conn) {
251 ALOGE("Failed to get DrmConnector for display %d", display_);
252 return -ENODEV;
253 }
254
255 const DrmProperty &prop = conn->dpms_property();
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +0100256 int ret = drmModeConnectorSetProperty(drm->fd(), conn->id(), prop.id(),
Sean Pauldb7a17d2015-06-24 18:46:05 -0700257 display_comp->dpms_mode());
258 if (ret) {
259 ALOGE("Failed to set DPMS property for connector %d", conn->id());
260 return ret;
261 }
262 return 0;
263}
264
Sean Paul35301f42015-11-17 14:46:56 -0500265std::tuple<int, uint32_t> DrmDisplayCompositor::CreateModeBlob(
266 const DrmMode &mode) {
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +0200267 struct drm_mode_modeinfo drm_mode {};
Sean Paul35301f42015-11-17 14:46:56 -0500268 mode.ToDrmModeModeInfo(&drm_mode);
269
270 uint32_t id = 0;
Alexandru Gheorghe62e2d2c2018-05-11 11:40:53 +0100271 DrmDevice *drm = resource_manager_->GetDrmDevice(display_);
272 int ret = drm->CreatePropertyBlob(&drm_mode, sizeof(struct drm_mode_modeinfo),
273 &id);
Sean Paul35301f42015-11-17 14:46:56 -0500274 if (ret) {
275 ALOGE("Failed to create mode property blob %d", ret);
276 return std::make_tuple(ret, 0);
277 }
Sean Paulf741c672016-05-11 13:49:38 -0400278 ALOGE("Create blob_id %" PRIu32 "\n", id);
Sean Paul35301f42015-11-17 14:46:56 -0500279 return std::make_tuple(ret, id);
280}
281
Sean Paul137a6a82016-06-22 22:48:22 -0400282void DrmDisplayCompositor::ClearDisplay() {
Sean Paul137a6a82016-06-22 22:48:22 -0400283 if (!active_composition_)
284 return;
285
286 if (DisablePlanes(active_composition_.get()))
287 return;
288
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200289 active_composition_.reset(nullptr);
Sean Paul137a6a82016-06-22 22:48:22 -0400290}
291
Haixia Shidda2fab2015-10-22 18:12:49 -0700292void DrmDisplayCompositor::ApplyFrame(
Roman Stratiienko74774712021-02-05 16:32:47 +0200293 std::unique_ptr<DrmDisplayComposition> composition, int status) {
Haixia Shidda2fab2015-10-22 18:12:49 -0700294 int ret = status;
295
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +0100296 if (!ret) {
Sean Paulc07b2112015-11-17 16:38:10 -0500297 ret = CommitFrame(composition.get(), false);
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +0100298 }
Haixia Shidda2fab2015-10-22 18:12:49 -0700299
300 if (ret) {
301 ALOGE("Composite failed for display %d", display_);
Haixia Shidda2fab2015-10-22 18:12:49 -0700302 // Disable the hw used by the last active composition. This allows us to
303 // signal the release fences from that composition to avoid hanging.
Sean Paul137a6a82016-06-22 22:48:22 -0400304 ClearDisplay();
305 return;
Haixia Shidda2fab2015-10-22 18:12:49 -0700306 }
307 ++dump_frames_composited_;
308
Haixia Shidda2fab2015-10-22 18:12:49 -0700309 active_composition_.swap(composition);
Haixia Shidda2fab2015-10-22 18:12:49 -0700310}
311
Sean Pauled45a8e2017-02-28 13:17:34 -0500312int DrmDisplayCompositor::ApplyComposition(
313 std::unique_ptr<DrmDisplayComposition> composition) {
314 int ret = 0;
Sean Paulacb2a442015-06-24 18:43:01 -0700315 switch (composition->type()) {
Zach Reiznerb4a9aef2015-07-16 09:45:59 -0700316 case DRM_COMPOSITION_TYPE_FRAME:
Haixia Shi6afbb6a2015-11-24 12:42:45 -0800317 if (composition->geometry_changed()) {
318 // Send the composition to the kernel to ensure we can commit it. This
Rob Herringaf0d9752018-05-04 16:34:19 -0500319 // is just a test, it won't actually commit the frame.
Haixia Shi6afbb6a2015-11-24 12:42:45 -0800320 ret = CommitFrame(composition.get(), true);
Rob Herringaf0d9752018-05-04 16:34:19 -0500321 if (ret) {
322 ALOGE("Commit test failed for display %d, FIXME", display_);
Sean Paul6c18b3b2015-11-25 11:04:25 -0500323 return ret;
Sean Paul647beb22015-11-19 13:55:48 -0500324 }
325 }
Rob Herringaf0d9752018-05-04 16:34:19 -0500326
Sean Pauled45a8e2017-02-28 13:17:34 -0500327 ApplyFrame(std::move(composition), ret);
Zach Reiznerb4a9aef2015-07-16 09:45:59 -0700328 break;
329 case DRM_COMPOSITION_TYPE_DPMS:
Sean Pauled45a8e2017-02-28 13:17:34 -0500330 active_ = (composition->dpms_mode() == DRM_MODE_DPMS_ON);
Zach Reiznerb4a9aef2015-07-16 09:45:59 -0700331 ret = ApplyDpms(composition.get());
332 if (ret)
333 ALOGE("Failed to apply dpms for display %d", display_);
Sean Paulacb2a442015-06-24 18:43:01 -0700334 return ret;
Sean Paul57355412015-09-19 09:14:34 -0400335 case DRM_COMPOSITION_TYPE_MODESET:
Sean Paul35301f42015-11-17 14:46:56 -0500336 mode_.mode = composition->display_mode();
337 if (mode_.blob_id)
Sean Paulf72cccd2018-08-27 13:59:08 -0400338 resource_manager_->GetDrmDevice(display_)->DestroyPropertyBlob(
339 mode_.blob_id);
Sean Paul35301f42015-11-17 14:46:56 -0500340 std::tie(ret, mode_.blob_id) = CreateModeBlob(mode_.mode);
341 if (ret) {
342 ALOGE("Failed to create mode blob for display %d", display_);
343 return ret;
344 }
345 mode_.needs_modeset = true;
Sean Paul57355412015-09-19 09:14:34 -0400346 return 0;
Zach Reiznerb4a9aef2015-07-16 09:45:59 -0700347 default:
348 ALOGE("Unknown composition type %d", composition->type());
349 return -EINVAL;
Sean Paul98e73c82015-06-24 14:38:49 -0700350 }
Sean Paul98e73c82015-06-24 14:38:49 -0700351
Sean Paul98e73c82015-06-24 14:38:49 -0700352 return ret;
353}
354
Rob Herring4f6c62e2018-05-17 14:33:02 -0500355int DrmDisplayCompositor::TestComposition(DrmDisplayComposition *composition) {
356 return CommitFrame(composition, true);
357}
358
Sean Paul98e73c82015-06-24 14:38:49 -0700359void DrmDisplayCompositor::Dump(std::ostringstream *out) const {
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700360 uint64_t num_frames = dump_frames_composited_;
361 dump_frames_composited_ = 0;
362
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +0200363 struct timespec ts {};
Roman Stratiienkoe8c06792021-09-30 10:09:31 +0300364 int ret = clock_gettime(CLOCK_MONOTONIC, &ts);
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700365 if (ret) {
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700366 return;
367 }
368
369 uint64_t cur_ts = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
370 uint64_t num_ms = (cur_ts - dump_last_timestamp_ns_) / (1000 * 1000);
Roman Stratiienkod26619b2021-08-04 19:55:37 +0300371 float fps = num_ms ? static_cast<float>(num_frames) * 1000.0F /
372 static_cast<float>(num_ms)
373 : 0.0F;
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700374
375 *out << "--DrmDisplayCompositor[" << display_
376 << "]: num_frames=" << num_frames << " num_ms=" << num_ms
377 << " fps=" << fps << "\n";
378
379 dump_last_timestamp_ns_ = cur_ts;
Sean Paul98e73c82015-06-24 14:38:49 -0700380}
Sean Paulf72cccd2018-08-27 13:59:08 -0400381} // namespace android