blob: 293160bfd0126c6ef32bc9ba86841694f6140c2c [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
Sean Paulaa18d912016-05-12 14:28:05 -0400382 std::vector<DrmPlane *> *container;
383 if (i.plane()->type() == DRM_PLANE_TYPE_PRIMARY)
384 container = primary_planes;
385 else
386 container = overlay_planes;
387 for (auto j = container->begin(); j != container->end(); ++j) {
388 if (*j == i.plane()) {
389 container->erase(j);
390 break;
391 }
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700392 }
393 }
Zach Reizner5757e822015-10-16 19:06:31 -0700394
Sean Paulaa18d912016-05-12 14:28:05 -0400395 return FinalizeComposition(exclude_rects.data(), exclude_rects.size());
Sean Paul4f4ef692016-05-03 16:40:59 -0700396}
397
398int DrmDisplayComposition::FinalizeComposition() {
Sean Paulaa18d912016-05-12 14:28:05 -0400399 return FinalizeComposition(NULL, 0);
400}
401
402int DrmDisplayComposition::FinalizeComposition(DrmHwcRect<int> *exclude_rects,
403 size_t num_exclude_rects) {
404 SeparateLayers(exclude_rects, num_exclude_rects);
Zach Reizner5757e822015-10-16 19:06:31 -0700405 return CreateAndAssignReleaseFences();
406}
407
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700408static const char *DrmCompositionTypeToString(DrmCompositionType type) {
409 switch (type) {
410 case DRM_COMPOSITION_TYPE_EMPTY:
411 return "EMPTY";
412 case DRM_COMPOSITION_TYPE_FRAME:
413 return "FRAME";
414 case DRM_COMPOSITION_TYPE_DPMS:
415 return "DPMS";
416 case DRM_COMPOSITION_TYPE_MODESET:
417 return "MODESET";
418 default:
419 return "<invalid>";
420 }
421}
422
423static const char *DPMSModeToString(int dpms_mode) {
424 switch (dpms_mode) {
425 case DRM_MODE_DPMS_ON:
426 return "ON";
427 case DRM_MODE_DPMS_OFF:
428 return "OFF";
429 default:
430 return "<invalid>";
431 }
432}
433
434static void DumpBuffer(const DrmHwcBuffer &buffer, std::ostringstream *out) {
435 if (!buffer) {
436 *out << "buffer=<invalid>";
437 return;
438 }
439
440 *out << "buffer[w/h/format]=";
441 *out << buffer->width << "/" << buffer->height << "/" << buffer->format;
442}
443
Sean Paul04b47ea2015-11-19 21:46:11 -0500444static void DumpTransform(uint32_t transform, std::ostringstream *out) {
445 *out << "[";
446
447 if (transform == 0)
448 *out << "IDENTITY";
449
450 bool separator = false;
451 if (transform & DrmHwcTransform::kFlipH) {
452 *out << "FLIPH";
453 separator = true;
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700454 }
Sean Paul04b47ea2015-11-19 21:46:11 -0500455 if (transform & DrmHwcTransform::kFlipV) {
456 if (separator)
457 *out << "|";
458 *out << "FLIPV";
459 separator = true;
460 }
461 if (transform & DrmHwcTransform::kRotate90) {
462 if (separator)
463 *out << "|";
464 *out << "ROTATE90";
465 separator = true;
466 }
467 if (transform & DrmHwcTransform::kRotate180) {
468 if (separator)
469 *out << "|";
470 *out << "ROTATE180";
471 separator = true;
472 }
473 if (transform & DrmHwcTransform::kRotate270) {
474 if (separator)
475 *out << "|";
476 *out << "ROTATE270";
477 separator = true;
478 }
479
480 uint32_t valid_bits = DrmHwcTransform::kFlipH | DrmHwcTransform::kFlipH |
481 DrmHwcTransform::kRotate90 |
482 DrmHwcTransform::kRotate180 |
483 DrmHwcTransform::kRotate270;
484 if (transform & ~valid_bits) {
485 if (separator)
486 *out << "|";
487 *out << "INVALID";
488 }
489 *out << "]";
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700490}
491
492static const char *BlendingToString(DrmHwcBlending blending) {
493 switch (blending) {
494 case DrmHwcBlending::kNone:
495 return "NONE";
496 case DrmHwcBlending::kPreMult:
497 return "PREMULT";
498 case DrmHwcBlending::kCoverage:
499 return "COVERAGE";
500 default:
501 return "<invalid>";
502 }
503}
504
505static void DumpRegion(const DrmCompositionRegion &region,
506 std::ostringstream *out) {
507 *out << "frame";
508 region.frame.Dump(out);
509 *out << " source_layers=(";
510
511 const std::vector<size_t> &source_layers = region.source_layers;
512 for (size_t i = 0; i < source_layers.size(); i++) {
513 *out << source_layers[i];
514 if (i < source_layers.size() - 1) {
515 *out << " ";
516 }
517 }
518
519 *out << ")";
520}
521
522void DrmDisplayComposition::Dump(std::ostringstream *out) const {
523 *out << "----DrmDisplayComposition"
524 << " crtc=" << (crtc_ ? crtc_->id() : -1)
525 << " type=" << DrmCompositionTypeToString(type_);
526
527 switch (type_) {
528 case DRM_COMPOSITION_TYPE_DPMS:
529 *out << " dpms_mode=" << DPMSModeToString(dpms_mode_);
530 break;
531 case DRM_COMPOSITION_TYPE_MODESET:
532 *out << " display_mode=" << display_mode_.h_display() << "x"
533 << display_mode_.v_display();
534 break;
535 default:
536 break;
537 }
538
539 *out << " timeline[current/squash/pre-comp/done]=" << timeline_current_ << "/"
540 << timeline_squash_done_ << "/" << timeline_pre_comp_done_ << "/"
541 << timeline_ << "\n";
542
543 *out << " Layers: count=" << layers_.size() << "\n";
544 for (size_t i = 0; i < layers_.size(); i++) {
545 const DrmHwcLayer &layer = layers_[i];
546 *out << " [" << i << "] ";
547
548 DumpBuffer(layer.buffer, out);
549
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700550 if (layer.protected_usage())
551 *out << " protected";
552
Sean Paul04b47ea2015-11-19 21:46:11 -0500553 *out << " transform=";
554 DumpTransform(layer.transform, out);
555 *out << " blending[a=" << (int)layer.alpha
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700556 << "]=" << BlendingToString(layer.blending) << " source_crop";
557 layer.source_crop.Dump(out);
558 *out << " display_frame";
559 layer.display_frame.Dump(out);
560
561 *out << "\n";
562 }
563
564 *out << " Planes: count=" << composition_planes_.size() << "\n";
565 for (size_t i = 0; i < composition_planes_.size(); i++) {
566 const DrmCompositionPlane &comp_plane = composition_planes_[i];
567 *out << " [" << i << "]"
Sean Paulca699be2016-05-11 16:29:45 -0400568 << " plane=" << (comp_plane.plane() ? comp_plane.plane()->id() : -1)
Sean Paul39b37842016-05-11 13:50:28 -0400569 << " type=";
Sean Paulca699be2016-05-11 16:29:45 -0400570 switch (comp_plane.type()) {
Sean Paulbbe39db2016-05-11 16:57:26 -0400571 case DrmCompositionPlane::Type::kDisable:
Sean Paul39b37842016-05-11 13:50:28 -0400572 *out << "DISABLE";
573 break;
Sean Paulbbe39db2016-05-11 16:57:26 -0400574 case DrmCompositionPlane::Type::kLayer:
Sean Paul39b37842016-05-11 13:50:28 -0400575 *out << "LAYER";
576 break;
Sean Paulbbe39db2016-05-11 16:57:26 -0400577 case DrmCompositionPlane::Type::kPrecomp:
Sean Paul39b37842016-05-11 13:50:28 -0400578 *out << "PRECOMP";
579 break;
Sean Paulbbe39db2016-05-11 16:57:26 -0400580 case DrmCompositionPlane::Type::kSquash:
Sean Paul39b37842016-05-11 13:50:28 -0400581 *out << "SQUASH";
582 break;
583 default:
584 *out << "<invalid>";
585 break;
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700586 }
587
Sean Paulca699be2016-05-11 16:29:45 -0400588 *out << " source_layer=";
589 for (auto i : comp_plane.source_layers()) {
590 *out << i << " ";
591 }
592 *out << "\n";
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700593 }
594
595 *out << " Squash Regions: count=" << squash_regions_.size() << "\n";
596 for (size_t i = 0; i < squash_regions_.size(); i++) {
597 *out << " [" << i << "] ";
598 DumpRegion(squash_regions_[i], out);
599 *out << "\n";
600 }
601
602 *out << " Pre-Comp Regions: count=" << pre_comp_regions_.size() << "\n";
603 for (size_t i = 0; i < pre_comp_regions_.size(); i++) {
604 *out << " [" << i << "] ";
605 DumpRegion(pre_comp_regions_[i], out);
606 *out << "\n";
607 }
608}
Sean Paul98e73c82015-06-24 14:38:49 -0700609}