blob: 0f8084b39706a1a4440b52842387b499a429d885 [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 LOG_TAG "hwc-drm-display-composition"
18
19#include "drmdisplaycomposition.h"
20#include "drmcrtc.h"
21#include "drmplane.h"
22#include "drmresources.h"
Sean Paulaa18d912016-05-12 14:28:05 -040023#include "platform.h"
Sean Paul98e73c82015-06-24 14:38:49 -070024
25#include <stdlib.h>
26
Zach Reizner92f8e632015-10-12 17:47:13 -070027#include <algorithm>
28#include <unordered_set>
29
Sean Paul98e73c82015-06-24 14:38:49 -070030#include <cutils/log.h>
31#include <sw_sync.h>
32#include <sync/sync.h>
Sean Pauldb7a17d2015-06-24 18:46:05 -070033#include <xf86drmMode.h>
Sean Paul98e73c82015-06-24 14:38:49 -070034
35namespace android {
36
Sean Paul98e73c82015-06-24 14:38:49 -070037DrmDisplayComposition::~DrmDisplayComposition() {
Zach Reiznerece04892015-07-17 14:13:28 -070038 if (timeline_fd_ >= 0) {
Zach Reizner92f8e632015-10-12 17:47:13 -070039 SignalCompositionDone();
Sean Paul98e73c82015-06-24 14:38:49 -070040 close(timeline_fd_);
Zach Reiznerece04892015-07-17 14:13:28 -070041 }
Sean Paul98e73c82015-06-24 14:38:49 -070042}
43
Zach Reizner09807052015-08-13 14:53:41 -070044int DrmDisplayComposition::Init(DrmResources *drm, DrmCrtc *crtc,
Sean Paulaa18d912016-05-12 14:28:05 -040045 Importer *importer, Planner *planner,
46 uint64_t frame_no) {
Sean Paul98e73c82015-06-24 14:38:49 -070047 drm_ = drm;
Zach Reizner4a253652015-09-10 18:30:54 -070048 crtc_ = crtc; // Can be NULL if we haven't modeset yet
Sean Paul98e73c82015-06-24 14:38:49 -070049 importer_ = importer;
Sean Paulaa18d912016-05-12 14:28:05 -040050 planner_ = planner;
Sean Paulbdc67bf2015-09-21 10:04:02 -040051 frame_no_ = frame_no;
Sean Paul98e73c82015-06-24 14:38:49 -070052
Zach Reizner4a253652015-09-10 18:30:54 -070053 int ret = sw_sync_timeline_create();
Sean Paul98e73c82015-06-24 14:38:49 -070054 if (ret < 0) {
55 ALOGE("Failed to create sw sync timeline %d", ret);
56 return ret;
57 }
58 timeline_fd_ = ret;
59 return 0;
60}
61
Sean Paulacb2a442015-06-24 18:43:01 -070062bool DrmDisplayComposition::validate_composition_type(DrmCompositionType des) {
63 return type_ == DRM_COMPOSITION_TYPE_EMPTY || type_ == des;
64}
65
Zach Reizner92f8e632015-10-12 17:47:13 -070066int DrmDisplayComposition::CreateNextTimelineFence() {
67 ++timeline_;
68 return sw_sync_fence_create(timeline_fd_, "hwc drm display composition fence",
69 timeline_);
70}
71
72int DrmDisplayComposition::IncreaseTimelineToPoint(int point) {
73 int timeline_increase = point - timeline_current_;
74 if (timeline_increase <= 0)
75 return 0;
76
77 int ret = sw_sync_timeline_inc(timeline_fd_, timeline_increase);
78 if (ret)
79 ALOGE("Failed to increment sync timeline %d", ret);
80 else
81 timeline_current_ = point;
82
83 return ret;
84}
85
Zach Reizner5757e822015-10-16 19:06:31 -070086int DrmDisplayComposition::SetLayers(DrmHwcLayer *layers, size_t num_layers,
87 bool geometry_changed) {
Zach Reizner92f8e632015-10-12 17:47:13 -070088 if (!validate_composition_type(DRM_COMPOSITION_TYPE_FRAME))
89 return -EINVAL;
90
Zach Reizner5757e822015-10-16 19:06:31 -070091 geometry_changed_ = geometry_changed;
92
Zach Reizner92f8e632015-10-12 17:47:13 -070093 for (size_t layer_index = 0; layer_index < num_layers; layer_index++) {
94 layers_.emplace_back(std::move(layers[layer_index]));
95 }
96
97 type_ = DRM_COMPOSITION_TYPE_FRAME;
98 return 0;
99}
100
101int DrmDisplayComposition::SetDpmsMode(uint32_t dpms_mode) {
102 if (!validate_composition_type(DRM_COMPOSITION_TYPE_DPMS))
103 return -EINVAL;
104 dpms_mode_ = dpms_mode;
105 type_ = DRM_COMPOSITION_TYPE_DPMS;
106 return 0;
107}
108
109int DrmDisplayComposition::SetDisplayMode(const DrmMode &display_mode) {
110 if (!validate_composition_type(DRM_COMPOSITION_TYPE_MODESET))
111 return -EINVAL;
112 display_mode_ = display_mode;
113 dpms_mode_ = DRM_MODE_DPMS_ON;
114 type_ = DRM_COMPOSITION_TYPE_MODESET;
115 return 0;
116}
117
118int DrmDisplayComposition::AddPlaneDisable(DrmPlane *plane) {
Sean Paulbbe39db2016-05-11 16:57:26 -0400119 composition_planes_.emplace_back(DrmCompositionPlane::Type::kDisable, plane,
Sean Paulca699be2016-05-11 16:29:45 -0400120 crtc_);
Zach Reizner92f8e632015-10-12 17:47:13 -0700121 return 0;
122}
123
Sean Paulaa18d912016-05-12 14:28:05 -0400124static std::vector<size_t> SetBitsToVector(
125 uint64_t in, const std::vector<size_t> &index_map) {
Zach Reizner92f8e632015-10-12 17:47:13 -0700126 std::vector<size_t> out;
127 size_t msb = sizeof(in) * 8 - 1;
128 uint64_t mask = (uint64_t)1 << msb;
129 for (size_t i = msb; mask != (uint64_t)0; i--, mask >>= 1)
130 if (in & mask)
131 out.push_back(index_map[i]);
132 return out;
Zach Reizner09807052015-08-13 14:53:41 -0700133}
Zach Reizner713a6782015-07-31 15:12:44 -0700134
Sean Paul4f4ef692016-05-03 16:40:59 -0700135int DrmDisplayComposition::AddPlaneComposition(DrmCompositionPlane plane) {
136 composition_planes_.emplace_back(std::move(plane));
137 return 0;
138}
139
Sean Paulaa18d912016-05-12 14:28:05 -0400140void DrmDisplayComposition::SeparateLayers(DrmHwcRect<int> *exclude_rects,
Sean Paul3960cdd2016-05-10 04:17:31 -0400141 size_t num_exclude_rects) {
142 DrmCompositionPlane *comp = NULL;
143 std::vector<size_t> dedicated_layers;
144
145 // Go through the composition and find the precomp layer as well as any
146 // layers that have a dedicated plane located below the precomp layer.
147 for (auto &i : composition_planes_) {
148 if (i.type() == DrmCompositionPlane::Type::kLayer) {
149 dedicated_layers.insert(dedicated_layers.end(), i.source_layers().begin(),
150 i.source_layers().end());
151 } else if (i.type() == DrmCompositionPlane::Type::kPrecomp) {
152 comp = &i;
153 break;
154 }
155 }
156 if (!comp)
157 return;
158
Sean Paulaa18d912016-05-12 14:28:05 -0400159 const std::vector<size_t> &comp_layers = comp->source_layers();
160 if (comp_layers.size() > 64) {
Zach Reizner92f8e632015-10-12 17:47:13 -0700161 ALOGE("Failed to separate layers because there are more than 64");
162 return;
163 }
Zach Reizner713a6782015-07-31 15:12:44 -0700164
Sean Paul8a628b92016-04-18 15:53:36 -0400165 // Index at which the actual layers begin
Sean Paul3960cdd2016-05-10 04:17:31 -0400166 size_t layer_offset = num_exclude_rects + dedicated_layers.size();
Sean Paulaa18d912016-05-12 14:28:05 -0400167 if (comp_layers.size() + layer_offset > 64) {
Zach Reizner92f8e632015-10-12 17:47:13 -0700168 ALOGW(
169 "Exclusion rectangles are being truncated to make the rectangle count "
170 "fit into 64");
Sean Paulaa18d912016-05-12 14:28:05 -0400171 num_exclude_rects = 64 - comp_layers.size() - dedicated_layers.size();
Zach Reizner92f8e632015-10-12 17:47:13 -0700172 }
Zach Reizner713a6782015-07-31 15:12:44 -0700173
Zach Reizner92f8e632015-10-12 17:47:13 -0700174 // We inject all the exclude rects into the rects list. Any resulting rect
Sean Paul8a628b92016-04-18 15:53:36 -0400175 // that includes ANY of the first num_exclude_rects is rejected. After the
Sean Paul3960cdd2016-05-10 04:17:31 -0400176 // exclude rects, we add the lower layers. The rects that intersect with
177 // these layers will be inspected and only those which are to be composited
178 // above the layer will be included in the composition regions.
Sean Paulaa18d912016-05-12 14:28:05 -0400179 std::vector<DrmHwcRect<int>> layer_rects(comp_layers.size() + layer_offset);
Zach Reizner92f8e632015-10-12 17:47:13 -0700180 std::copy(exclude_rects, exclude_rects + num_exclude_rects,
181 layer_rects.begin());
182 std::transform(
Sean Paul3960cdd2016-05-10 04:17:31 -0400183 dedicated_layers.begin(), dedicated_layers.end(),
Zach Reizner92f8e632015-10-12 17:47:13 -0700184 layer_rects.begin() + num_exclude_rects,
Sean Paul3960cdd2016-05-10 04:17:31 -0400185 [=](size_t layer_index) { return layers_[layer_index].display_frame; });
Sean Paulaa18d912016-05-12 14:28:05 -0400186 std::transform(comp_layers.begin(), comp_layers.end(),
Sean Paul3960cdd2016-05-10 04:17:31 -0400187 layer_rects.begin() + layer_offset, [=](size_t layer_index) {
188 return layers_[layer_index].display_frame;
189 });
Zach Reizner92f8e632015-10-12 17:47:13 -0700190
Haixia Shiaa2f4a52015-11-02 10:54:29 -0800191 std::vector<separate_rects::RectSet<uint64_t, int>> separate_regions;
192 separate_rects::separate_rects_64(layer_rects, &separate_regions);
Zach Reizner92f8e632015-10-12 17:47:13 -0700193 uint64_t exclude_mask = ((uint64_t)1 << num_exclude_rects) - 1;
Sean Paul3960cdd2016-05-10 04:17:31 -0400194 uint64_t dedicated_mask = (((uint64_t)1 << dedicated_layers.size()) - 1)
195 << num_exclude_rects;
Zach Reizner92f8e632015-10-12 17:47:13 -0700196
Haixia Shiaa2f4a52015-11-02 10:54:29 -0800197 for (separate_rects::RectSet<uint64_t, int> &region : separate_regions) {
Zach Reizner92f8e632015-10-12 17:47:13 -0700198 if (region.id_set.getBits() & exclude_mask)
199 continue;
Sean Paul8a628b92016-04-18 15:53:36 -0400200
Sean Paul3960cdd2016-05-10 04:17:31 -0400201 // If a rect intersects one of the dedicated layers, we need to remove the
202 // layers from the composition region which appear *below* the dedicated
203 // layer. This effectively punches a hole through the composition layer such
204 // that the dedicated layer can be placed below the composition and not
205 // be occluded.
206 uint64_t dedicated_intersect = region.id_set.getBits() & dedicated_mask;
207 for (size_t i = 0; dedicated_intersect && i < dedicated_layers.size();
208 ++i) {
209 // Only exclude layers if they intersect this particular dedicated layer
210 if (!(dedicated_intersect & (1 << (i + num_exclude_rects))))
Sean Paul8a628b92016-04-18 15:53:36 -0400211 continue;
212
Sean Paulaa18d912016-05-12 14:28:05 -0400213 for (size_t j = 0; j < comp_layers.size(); ++j) {
214 if (comp_layers[j] < dedicated_layers[i])
Sean Paulf1d25792016-05-10 03:42:55 -0400215 region.id_set.subtract(j + layer_offset);
216 }
Sean Paul8a628b92016-04-18 15:53:36 -0400217 }
Sean Paulf1d25792016-05-10 03:42:55 -0400218 if (!(region.id_set.getBits() >> layer_offset))
Sean Paul8a628b92016-04-18 15:53:36 -0400219 continue;
220
Sean Paul3960cdd2016-05-10 04:17:31 -0400221 pre_comp_regions_.emplace_back(DrmCompositionRegion{
Zach Reizner92f8e632015-10-12 17:47:13 -0700222 region.rect,
Sean Paulaa18d912016-05-12 14:28:05 -0400223 SetBitsToVector(region.id_set.getBits() >> layer_offset, comp_layers)});
Zach Reizner92f8e632015-10-12 17:47:13 -0700224 }
Zach Reizner713a6782015-07-31 15:12:44 -0700225}
226
Zach Reizner5757e822015-10-16 19:06:31 -0700227int DrmDisplayComposition::CreateAndAssignReleaseFences() {
Zach Reizner92f8e632015-10-12 17:47:13 -0700228 std::unordered_set<DrmHwcLayer *> squash_layers;
229 std::unordered_set<DrmHwcLayer *> pre_comp_layers;
230 std::unordered_set<DrmHwcLayer *> comp_layers;
231
232 for (const DrmCompositionRegion &region : squash_regions_) {
233 for (size_t source_layer_index : region.source_layers) {
234 DrmHwcLayer *source_layer = &layers_[source_layer_index];
235 squash_layers.emplace(source_layer);
236 }
237 }
238
239 for (const DrmCompositionRegion &region : pre_comp_regions_) {
240 for (size_t source_layer_index : region.source_layers) {
241 DrmHwcLayer *source_layer = &layers_[source_layer_index];
242 pre_comp_layers.emplace(source_layer);
243 squash_layers.erase(source_layer);
244 }
245 }
246
247 for (const DrmCompositionPlane &plane : composition_planes_) {
Sean Paulbbe39db2016-05-11 16:57:26 -0400248 if (plane.type() == DrmCompositionPlane::Type::kLayer) {
Sean Paulca699be2016-05-11 16:29:45 -0400249 for (auto i : plane.source_layers()) {
250 DrmHwcLayer *source_layer = &layers_[i];
251 comp_layers.emplace(source_layer);
252 pre_comp_layers.erase(source_layer);
253 }
Zach Reizner92f8e632015-10-12 17:47:13 -0700254 }
255 }
256
257 for (DrmHwcLayer *layer : squash_layers) {
Zach Reiznercb1cfc82015-11-13 16:11:37 -0800258 if (!layer->release_fence)
259 continue;
Zach Reizner92f8e632015-10-12 17:47:13 -0700260 int ret = layer->release_fence.Set(CreateNextTimelineFence());
Sean Paul8600e342017-02-28 13:25:26 -0500261 if (ret < 0) {
262 ALOGE("Failed to set the release fence (squash) %d", ret);
Zach Reizner92f8e632015-10-12 17:47:13 -0700263 return ret;
Sean Paul8600e342017-02-28 13:25:26 -0500264 }
Zach Reizner92f8e632015-10-12 17:47:13 -0700265 }
266 timeline_squash_done_ = timeline_;
267
268 for (DrmHwcLayer *layer : pre_comp_layers) {
Zach Reiznercb1cfc82015-11-13 16:11:37 -0800269 if (!layer->release_fence)
270 continue;
Zach Reizner92f8e632015-10-12 17:47:13 -0700271 int ret = layer->release_fence.Set(CreateNextTimelineFence());
272 if (ret < 0)
273 return ret;
274 }
Zach Reizner09807052015-08-13 14:53:41 -0700275 timeline_pre_comp_done_ = timeline_;
276
Zach Reizner92f8e632015-10-12 17:47:13 -0700277 for (DrmHwcLayer *layer : comp_layers) {
Zach Reiznercb1cfc82015-11-13 16:11:37 -0800278 if (!layer->release_fence)
279 continue;
Zach Reizner92f8e632015-10-12 17:47:13 -0700280 int ret = layer->release_fence.Set(CreateNextTimelineFence());
Sean Paul8600e342017-02-28 13:25:26 -0500281 if (ret < 0) {
282 ALOGE("Failed to set the release fence (comp) %d", ret);
Zach Reizner92f8e632015-10-12 17:47:13 -0700283 return ret;
Sean Paul8600e342017-02-28 13:25:26 -0500284 }
Zach Reizner09807052015-08-13 14:53:41 -0700285 }
286
Zach Reizner09807052015-08-13 14:53:41 -0700287 return 0;
Zach Reizner46ddd452015-07-30 08:10:14 -0700288}
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700289
Zach Reizner5757e822015-10-16 19:06:31 -0700290int DrmDisplayComposition::Plan(SquashState *squash,
291 std::vector<DrmPlane *> *primary_planes,
292 std::vector<DrmPlane *> *overlay_planes) {
293 if (type_ != DRM_COMPOSITION_TYPE_FRAME)
294 return 0;
295
Sean Paulaa18d912016-05-12 14:28:05 -0400296 // Used to track which layers should be sent to the planner. We exclude layers
297 // that are entirely squashed so the planner can provision a precomposition
298 // layer as appropriate (ex: if 5 layers are squashed and 1 is not, we don't
299 // want to plan a precomposition layer that will be comprised of the already
300 // squashed layers).
301 std::map<size_t, DrmHwcLayer *> to_composite;
Zach Reizner5757e822015-10-16 19:06:31 -0700302
303 bool use_squash_framebuffer = false;
304 // Used to determine which layers were entirely squashed
305 std::vector<int> layer_squash_area(layers_.size(), 0);
306 // Used to avoid rerendering regions that were squashed
307 std::vector<DrmHwcRect<int>> exclude_rects;
Sean Paulaa18d912016-05-12 14:28:05 -0400308 if (squash != NULL) {
Zach Reizner5757e822015-10-16 19:06:31 -0700309 if (geometry_changed_) {
310 squash->Init(layers_.data(), layers_.size());
311 } else {
312 std::vector<bool> changed_regions;
313 squash->GenerateHistory(layers_.data(), layers_.size(), changed_regions);
314
315 std::vector<bool> stable_regions;
316 squash->StableRegionsWithMarginalHistory(changed_regions, stable_regions);
317
318 // Only if SOME region is stable
319 use_squash_framebuffer =
320 std::find(stable_regions.begin(), stable_regions.end(), true) !=
321 stable_regions.end();
322
323 squash->RecordHistory(layers_.data(), layers_.size(), changed_regions);
324
325 // Changes in which regions are squashed triggers a rerender via
326 // squash_regions.
327 bool render_squash = squash->RecordAndCompareSquashed(stable_regions);
328
329 for (size_t region_index = 0; region_index < stable_regions.size();
330 region_index++) {
331 const SquashState::Region &region = squash->regions()[region_index];
332 if (!stable_regions[region_index])
333 continue;
334
335 exclude_rects.emplace_back(region.rect);
336
337 if (render_squash) {
338 squash_regions_.emplace_back();
339 squash_regions_.back().frame = region.rect;
340 }
341
342 int frame_area = region.rect.area();
343 // Source layers are sorted front to back i.e. top layer has lowest
344 // index.
345 for (size_t layer_index = layers_.size();
346 layer_index-- > 0; // Yes, I double checked this
347 /* See condition */) {
348 if (!region.layer_refs[layer_index])
349 continue;
350 layer_squash_area[layer_index] += frame_area;
351 if (render_squash)
352 squash_regions_.back().source_layers.push_back(layer_index);
353 }
354 }
355 }
Sean Paulaa18d912016-05-12 14:28:05 -0400356
357 for (size_t i = 0; i < layers_.size(); ++i) {
358 if (layer_squash_area[i] < layers_[i].display_frame.area())
359 to_composite.emplace(std::make_pair(i, &layers_[i]));
360 }
361 } else {
362 for (size_t i = 0; i < layers_.size(); ++i)
363 to_composite.emplace(std::make_pair(i, &layers_[i]));
Zach Reizner5757e822015-10-16 19:06:31 -0700364 }
365
Sean Paulaa18d912016-05-12 14:28:05 -0400366 int ret;
367 std::vector<DrmCompositionPlane> plan;
368 std::tie(ret, composition_planes_) =
369 planner_->ProvisionPlanes(to_composite, use_squash_framebuffer, crtc_,
370 primary_planes, overlay_planes);
371 if (ret) {
372 ALOGE("Planner failed provisioning planes ret=%d", ret);
373 return ret;
374 }
375
376 // Remove the planes we used from the pool before returning. This ensures they
377 // won't be reused by another display in the composition.
378 for (auto &i : composition_planes_) {
379 if (!i.plane())
Zach Reizner5757e822015-10-16 19:06:31 -0700380 continue;
Zach Reizner5757e822015-10-16 19:06:31 -0700381
Adrian Salido1a1cf9b2017-09-21 16:53:48 -0700382 // make sure that source layers are ordered based on zorder
383 std::sort(i.source_layers().begin(), i.source_layers().end());
384
Sean Paulaa18d912016-05-12 14:28:05 -0400385 std::vector<DrmPlane *> *container;
386 if (i.plane()->type() == DRM_PLANE_TYPE_PRIMARY)
387 container = primary_planes;
388 else
389 container = overlay_planes;
390 for (auto j = container->begin(); j != container->end(); ++j) {
391 if (*j == i.plane()) {
392 container->erase(j);
393 break;
394 }
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700395 }
396 }
Zach Reizner5757e822015-10-16 19:06:31 -0700397
Sean Paulaa18d912016-05-12 14:28:05 -0400398 return FinalizeComposition(exclude_rects.data(), exclude_rects.size());
Sean Paul4f4ef692016-05-03 16:40:59 -0700399}
400
401int DrmDisplayComposition::FinalizeComposition() {
Sean Paulaa18d912016-05-12 14:28:05 -0400402 return FinalizeComposition(NULL, 0);
403}
404
405int DrmDisplayComposition::FinalizeComposition(DrmHwcRect<int> *exclude_rects,
406 size_t num_exclude_rects) {
407 SeparateLayers(exclude_rects, num_exclude_rects);
Zach Reizner5757e822015-10-16 19:06:31 -0700408 return CreateAndAssignReleaseFences();
409}
410
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700411static const char *DrmCompositionTypeToString(DrmCompositionType type) {
412 switch (type) {
413 case DRM_COMPOSITION_TYPE_EMPTY:
414 return "EMPTY";
415 case DRM_COMPOSITION_TYPE_FRAME:
416 return "FRAME";
417 case DRM_COMPOSITION_TYPE_DPMS:
418 return "DPMS";
419 case DRM_COMPOSITION_TYPE_MODESET:
420 return "MODESET";
421 default:
422 return "<invalid>";
423 }
424}
425
426static const char *DPMSModeToString(int dpms_mode) {
427 switch (dpms_mode) {
428 case DRM_MODE_DPMS_ON:
429 return "ON";
430 case DRM_MODE_DPMS_OFF:
431 return "OFF";
432 default:
433 return "<invalid>";
434 }
435}
436
437static void DumpBuffer(const DrmHwcBuffer &buffer, std::ostringstream *out) {
438 if (!buffer) {
439 *out << "buffer=<invalid>";
440 return;
441 }
442
443 *out << "buffer[w/h/format]=";
444 *out << buffer->width << "/" << buffer->height << "/" << buffer->format;
445}
446
Sean Paul04b47ea2015-11-19 21:46:11 -0500447static void DumpTransform(uint32_t transform, std::ostringstream *out) {
448 *out << "[";
449
450 if (transform == 0)
451 *out << "IDENTITY";
452
453 bool separator = false;
454 if (transform & DrmHwcTransform::kFlipH) {
455 *out << "FLIPH";
456 separator = true;
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700457 }
Sean Paul04b47ea2015-11-19 21:46:11 -0500458 if (transform & DrmHwcTransform::kFlipV) {
459 if (separator)
460 *out << "|";
461 *out << "FLIPV";
462 separator = true;
463 }
464 if (transform & DrmHwcTransform::kRotate90) {
465 if (separator)
466 *out << "|";
467 *out << "ROTATE90";
468 separator = true;
469 }
470 if (transform & DrmHwcTransform::kRotate180) {
471 if (separator)
472 *out << "|";
473 *out << "ROTATE180";
474 separator = true;
475 }
476 if (transform & DrmHwcTransform::kRotate270) {
477 if (separator)
478 *out << "|";
479 *out << "ROTATE270";
480 separator = true;
481 }
482
483 uint32_t valid_bits = DrmHwcTransform::kFlipH | DrmHwcTransform::kFlipH |
484 DrmHwcTransform::kRotate90 |
485 DrmHwcTransform::kRotate180 |
486 DrmHwcTransform::kRotate270;
487 if (transform & ~valid_bits) {
488 if (separator)
489 *out << "|";
490 *out << "INVALID";
491 }
492 *out << "]";
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700493}
494
495static const char *BlendingToString(DrmHwcBlending blending) {
496 switch (blending) {
497 case DrmHwcBlending::kNone:
498 return "NONE";
499 case DrmHwcBlending::kPreMult:
500 return "PREMULT";
501 case DrmHwcBlending::kCoverage:
502 return "COVERAGE";
503 default:
504 return "<invalid>";
505 }
506}
507
508static void DumpRegion(const DrmCompositionRegion &region,
509 std::ostringstream *out) {
510 *out << "frame";
511 region.frame.Dump(out);
512 *out << " source_layers=(";
513
514 const std::vector<size_t> &source_layers = region.source_layers;
515 for (size_t i = 0; i < source_layers.size(); i++) {
516 *out << source_layers[i];
517 if (i < source_layers.size() - 1) {
518 *out << " ";
519 }
520 }
521
522 *out << ")";
523}
524
525void DrmDisplayComposition::Dump(std::ostringstream *out) const {
526 *out << "----DrmDisplayComposition"
527 << " crtc=" << (crtc_ ? crtc_->id() : -1)
528 << " type=" << DrmCompositionTypeToString(type_);
529
530 switch (type_) {
531 case DRM_COMPOSITION_TYPE_DPMS:
532 *out << " dpms_mode=" << DPMSModeToString(dpms_mode_);
533 break;
534 case DRM_COMPOSITION_TYPE_MODESET:
535 *out << " display_mode=" << display_mode_.h_display() << "x"
536 << display_mode_.v_display();
537 break;
538 default:
539 break;
540 }
541
542 *out << " timeline[current/squash/pre-comp/done]=" << timeline_current_ << "/"
543 << timeline_squash_done_ << "/" << timeline_pre_comp_done_ << "/"
544 << timeline_ << "\n";
545
546 *out << " Layers: count=" << layers_.size() << "\n";
547 for (size_t i = 0; i < layers_.size(); i++) {
548 const DrmHwcLayer &layer = layers_[i];
549 *out << " [" << i << "] ";
550
551 DumpBuffer(layer.buffer, out);
552
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700553 if (layer.protected_usage())
554 *out << " protected";
555
Sean Paul04b47ea2015-11-19 21:46:11 -0500556 *out << " transform=";
557 DumpTransform(layer.transform, out);
558 *out << " blending[a=" << (int)layer.alpha
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700559 << "]=" << BlendingToString(layer.blending) << " source_crop";
560 layer.source_crop.Dump(out);
561 *out << " display_frame";
562 layer.display_frame.Dump(out);
563
564 *out << "\n";
565 }
566
567 *out << " Planes: count=" << composition_planes_.size() << "\n";
568 for (size_t i = 0; i < composition_planes_.size(); i++) {
569 const DrmCompositionPlane &comp_plane = composition_planes_[i];
570 *out << " [" << i << "]"
Sean Paulca699be2016-05-11 16:29:45 -0400571 << " plane=" << (comp_plane.plane() ? comp_plane.plane()->id() : -1)
Sean Paul39b37842016-05-11 13:50:28 -0400572 << " type=";
Sean Paulca699be2016-05-11 16:29:45 -0400573 switch (comp_plane.type()) {
Sean Paulbbe39db2016-05-11 16:57:26 -0400574 case DrmCompositionPlane::Type::kDisable:
Sean Paul39b37842016-05-11 13:50:28 -0400575 *out << "DISABLE";
576 break;
Sean Paulbbe39db2016-05-11 16:57:26 -0400577 case DrmCompositionPlane::Type::kLayer:
Sean Paul39b37842016-05-11 13:50:28 -0400578 *out << "LAYER";
579 break;
Sean Paulbbe39db2016-05-11 16:57:26 -0400580 case DrmCompositionPlane::Type::kPrecomp:
Sean Paul39b37842016-05-11 13:50:28 -0400581 *out << "PRECOMP";
582 break;
Sean Paulbbe39db2016-05-11 16:57:26 -0400583 case DrmCompositionPlane::Type::kSquash:
Sean Paul39b37842016-05-11 13:50:28 -0400584 *out << "SQUASH";
585 break;
586 default:
587 *out << "<invalid>";
588 break;
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700589 }
590
Sean Paulca699be2016-05-11 16:29:45 -0400591 *out << " source_layer=";
592 for (auto i : comp_plane.source_layers()) {
593 *out << i << " ";
594 }
595 *out << "\n";
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700596 }
597
598 *out << " Squash Regions: count=" << squash_regions_.size() << "\n";
599 for (size_t i = 0; i < squash_regions_.size(); i++) {
600 *out << " [" << i << "] ";
601 DumpRegion(squash_regions_[i], out);
602 *out << "\n";
603 }
604
605 *out << " Pre-Comp Regions: count=" << pre_comp_regions_.size() << "\n";
606 for (size_t i = 0; i < pre_comp_regions_.size(); i++) {
607 *out << " [" << i << "] ";
608 DumpRegion(pre_comp_regions_[i], out);
609 *out << "\n";
610 }
611}
Sean Paul98e73c82015-06-24 14:38:49 -0700612}