blob: 24a8e9c9a04369c208c833adfca7a729565d75c0 [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"
Sean Pauled45a8e2017-02-28 13:17:34 -050020#include "drmdisplaycompositor.h"
Sean Paul98e73c82015-06-24 14:38:49 -070021#include "drmcrtc.h"
22#include "drmplane.h"
23#include "drmresources.h"
Sean Paulaa18d912016-05-12 14:28:05 -040024#include "platform.h"
Sean Paul98e73c82015-06-24 14:38:49 -070025
26#include <stdlib.h>
27
Zach Reizner92f8e632015-10-12 17:47:13 -070028#include <algorithm>
29#include <unordered_set>
30
John Stultz9057a6f2018-04-26 12:05:55 -070031#include <log/log.h>
Sean Paul98e73c82015-06-24 14:38:49 -070032#include <sw_sync.h>
33#include <sync/sync.h>
Sean Pauldb7a17d2015-06-24 18:46:05 -070034#include <xf86drmMode.h>
Sean Paul98e73c82015-06-24 14:38:49 -070035
36namespace android {
37
Sean Paul98e73c82015-06-24 14:38:49 -070038DrmDisplayComposition::~DrmDisplayComposition() {
Zach Reiznerece04892015-07-17 14:13:28 -070039 if (timeline_fd_ >= 0) {
Zach Reizner92f8e632015-10-12 17:47:13 -070040 SignalCompositionDone();
Sean Paul98e73c82015-06-24 14:38:49 -070041 close(timeline_fd_);
Zach Reiznerece04892015-07-17 14:13:28 -070042 }
Sean Paul98e73c82015-06-24 14:38:49 -070043}
44
Zach Reizner09807052015-08-13 14:53:41 -070045int DrmDisplayComposition::Init(DrmResources *drm, DrmCrtc *crtc,
Sean Paulaa18d912016-05-12 14:28:05 -040046 Importer *importer, Planner *planner,
47 uint64_t frame_no) {
Sean Paul98e73c82015-06-24 14:38:49 -070048 drm_ = drm;
Zach Reizner4a253652015-09-10 18:30:54 -070049 crtc_ = crtc; // Can be NULL if we haven't modeset yet
Sean Paul98e73c82015-06-24 14:38:49 -070050 importer_ = importer;
Sean Paulaa18d912016-05-12 14:28:05 -040051 planner_ = planner;
Sean Paulbdc67bf2015-09-21 10:04:02 -040052 frame_no_ = frame_no;
Sean Paul98e73c82015-06-24 14:38:49 -070053
Zach Reizner4a253652015-09-10 18:30:54 -070054 int ret = sw_sync_timeline_create();
Sean Paul98e73c82015-06-24 14:38:49 -070055 if (ret < 0) {
56 ALOGE("Failed to create sw sync timeline %d", ret);
57 return ret;
58 }
59 timeline_fd_ = ret;
60 return 0;
61}
62
Sean Paulacb2a442015-06-24 18:43:01 -070063bool DrmDisplayComposition::validate_composition_type(DrmCompositionType des) {
64 return type_ == DRM_COMPOSITION_TYPE_EMPTY || type_ == des;
65}
66
Zach Reizner92f8e632015-10-12 17:47:13 -070067int DrmDisplayComposition::CreateNextTimelineFence() {
68 ++timeline_;
69 return sw_sync_fence_create(timeline_fd_, "hwc drm display composition fence",
70 timeline_);
71}
72
73int DrmDisplayComposition::IncreaseTimelineToPoint(int point) {
74 int timeline_increase = point - timeline_current_;
75 if (timeline_increase <= 0)
76 return 0;
77
78 int ret = sw_sync_timeline_inc(timeline_fd_, timeline_increase);
79 if (ret)
80 ALOGE("Failed to increment sync timeline %d", ret);
81 else
82 timeline_current_ = point;
83
84 return ret;
85}
86
Zach Reizner5757e822015-10-16 19:06:31 -070087int DrmDisplayComposition::SetLayers(DrmHwcLayer *layers, size_t num_layers,
88 bool geometry_changed) {
Zach Reizner92f8e632015-10-12 17:47:13 -070089 if (!validate_composition_type(DRM_COMPOSITION_TYPE_FRAME))
90 return -EINVAL;
91
Zach Reizner5757e822015-10-16 19:06:31 -070092 geometry_changed_ = geometry_changed;
93
Zach Reizner92f8e632015-10-12 17:47:13 -070094 for (size_t layer_index = 0; layer_index < num_layers; layer_index++) {
95 layers_.emplace_back(std::move(layers[layer_index]));
96 }
97
98 type_ = DRM_COMPOSITION_TYPE_FRAME;
99 return 0;
100}
101
102int DrmDisplayComposition::SetDpmsMode(uint32_t dpms_mode) {
103 if (!validate_composition_type(DRM_COMPOSITION_TYPE_DPMS))
104 return -EINVAL;
105 dpms_mode_ = dpms_mode;
106 type_ = DRM_COMPOSITION_TYPE_DPMS;
107 return 0;
108}
109
110int DrmDisplayComposition::SetDisplayMode(const DrmMode &display_mode) {
111 if (!validate_composition_type(DRM_COMPOSITION_TYPE_MODESET))
112 return -EINVAL;
113 display_mode_ = display_mode;
114 dpms_mode_ = DRM_MODE_DPMS_ON;
115 type_ = DRM_COMPOSITION_TYPE_MODESET;
116 return 0;
117}
118
119int DrmDisplayComposition::AddPlaneDisable(DrmPlane *plane) {
Sean Paulbbe39db2016-05-11 16:57:26 -0400120 composition_planes_.emplace_back(DrmCompositionPlane::Type::kDisable, plane,
Sean Paulca699be2016-05-11 16:29:45 -0400121 crtc_);
Zach Reizner92f8e632015-10-12 17:47:13 -0700122 return 0;
123}
124
Sean Paulaa18d912016-05-12 14:28:05 -0400125static std::vector<size_t> SetBitsToVector(
126 uint64_t in, const std::vector<size_t> &index_map) {
Zach Reizner92f8e632015-10-12 17:47:13 -0700127 std::vector<size_t> out;
128 size_t msb = sizeof(in) * 8 - 1;
129 uint64_t mask = (uint64_t)1 << msb;
130 for (size_t i = msb; mask != (uint64_t)0; i--, mask >>= 1)
131 if (in & mask)
132 out.push_back(index_map[i]);
133 return out;
Zach Reizner09807052015-08-13 14:53:41 -0700134}
Zach Reizner713a6782015-07-31 15:12:44 -0700135
Sean Paul4f4ef692016-05-03 16:40:59 -0700136int DrmDisplayComposition::AddPlaneComposition(DrmCompositionPlane plane) {
137 composition_planes_.emplace_back(std::move(plane));
138 return 0;
139}
140
Sean Paulaa18d912016-05-12 14:28:05 -0400141void DrmDisplayComposition::SeparateLayers(DrmHwcRect<int> *exclude_rects,
Sean Paul3960cdd2016-05-10 04:17:31 -0400142 size_t num_exclude_rects) {
143 DrmCompositionPlane *comp = NULL;
144 std::vector<size_t> dedicated_layers;
145
146 // Go through the composition and find the precomp layer as well as any
147 // layers that have a dedicated plane located below the precomp layer.
148 for (auto &i : composition_planes_) {
149 if (i.type() == DrmCompositionPlane::Type::kLayer) {
150 dedicated_layers.insert(dedicated_layers.end(), i.source_layers().begin(),
151 i.source_layers().end());
152 } else if (i.type() == DrmCompositionPlane::Type::kPrecomp) {
153 comp = &i;
154 break;
155 }
156 }
157 if (!comp)
158 return;
159
Sean Paulaa18d912016-05-12 14:28:05 -0400160 const std::vector<size_t> &comp_layers = comp->source_layers();
161 if (comp_layers.size() > 64) {
Zach Reizner92f8e632015-10-12 17:47:13 -0700162 ALOGE("Failed to separate layers because there are more than 64");
163 return;
164 }
Zach Reizner713a6782015-07-31 15:12:44 -0700165
Sean Paul8a628b92016-04-18 15:53:36 -0400166 // Index at which the actual layers begin
Sean Paul3960cdd2016-05-10 04:17:31 -0400167 size_t layer_offset = num_exclude_rects + dedicated_layers.size();
Sean Paulaa18d912016-05-12 14:28:05 -0400168 if (comp_layers.size() + layer_offset > 64) {
Zach Reizner92f8e632015-10-12 17:47:13 -0700169 ALOGW(
170 "Exclusion rectangles are being truncated to make the rectangle count "
171 "fit into 64");
Sean Paulaa18d912016-05-12 14:28:05 -0400172 num_exclude_rects = 64 - comp_layers.size() - dedicated_layers.size();
Zach Reizner92f8e632015-10-12 17:47:13 -0700173 }
Zach Reizner713a6782015-07-31 15:12:44 -0700174
Zach Reizner92f8e632015-10-12 17:47:13 -0700175 // We inject all the exclude rects into the rects list. Any resulting rect
Sean Paul8a628b92016-04-18 15:53:36 -0400176 // that includes ANY of the first num_exclude_rects is rejected. After the
Sean Paul3960cdd2016-05-10 04:17:31 -0400177 // exclude rects, we add the lower layers. The rects that intersect with
178 // these layers will be inspected and only those which are to be composited
179 // above the layer will be included in the composition regions.
Sean Paulaa18d912016-05-12 14:28:05 -0400180 std::vector<DrmHwcRect<int>> layer_rects(comp_layers.size() + layer_offset);
Zach Reizner92f8e632015-10-12 17:47:13 -0700181 std::copy(exclude_rects, exclude_rects + num_exclude_rects,
182 layer_rects.begin());
183 std::transform(
Sean Paul3960cdd2016-05-10 04:17:31 -0400184 dedicated_layers.begin(), dedicated_layers.end(),
Zach Reizner92f8e632015-10-12 17:47:13 -0700185 layer_rects.begin() + num_exclude_rects,
Sean Paul3960cdd2016-05-10 04:17:31 -0400186 [=](size_t layer_index) { return layers_[layer_index].display_frame; });
Sean Paulaa18d912016-05-12 14:28:05 -0400187 std::transform(comp_layers.begin(), comp_layers.end(),
Sean Paul3960cdd2016-05-10 04:17:31 -0400188 layer_rects.begin() + layer_offset, [=](size_t layer_index) {
189 return layers_[layer_index].display_frame;
190 });
Zach Reizner92f8e632015-10-12 17:47:13 -0700191
Haixia Shiaa2f4a52015-11-02 10:54:29 -0800192 std::vector<separate_rects::RectSet<uint64_t, int>> separate_regions;
193 separate_rects::separate_rects_64(layer_rects, &separate_regions);
Zach Reizner92f8e632015-10-12 17:47:13 -0700194 uint64_t exclude_mask = ((uint64_t)1 << num_exclude_rects) - 1;
Sean Paul3960cdd2016-05-10 04:17:31 -0400195 uint64_t dedicated_mask = (((uint64_t)1 << dedicated_layers.size()) - 1)
196 << num_exclude_rects;
Zach Reizner92f8e632015-10-12 17:47:13 -0700197
Haixia Shiaa2f4a52015-11-02 10:54:29 -0800198 for (separate_rects::RectSet<uint64_t, int> &region : separate_regions) {
Zach Reizner92f8e632015-10-12 17:47:13 -0700199 if (region.id_set.getBits() & exclude_mask)
200 continue;
Sean Paul8a628b92016-04-18 15:53:36 -0400201
Sean Paul3960cdd2016-05-10 04:17:31 -0400202 // If a rect intersects one of the dedicated layers, we need to remove the
203 // layers from the composition region which appear *below* the dedicated
204 // layer. This effectively punches a hole through the composition layer such
205 // that the dedicated layer can be placed below the composition and not
206 // be occluded.
207 uint64_t dedicated_intersect = region.id_set.getBits() & dedicated_mask;
208 for (size_t i = 0; dedicated_intersect && i < dedicated_layers.size();
209 ++i) {
210 // Only exclude layers if they intersect this particular dedicated layer
211 if (!(dedicated_intersect & (1 << (i + num_exclude_rects))))
Sean Paul8a628b92016-04-18 15:53:36 -0400212 continue;
213
Sean Paulaa18d912016-05-12 14:28:05 -0400214 for (size_t j = 0; j < comp_layers.size(); ++j) {
215 if (comp_layers[j] < dedicated_layers[i])
Sean Paulf1d25792016-05-10 03:42:55 -0400216 region.id_set.subtract(j + layer_offset);
217 }
Sean Paul8a628b92016-04-18 15:53:36 -0400218 }
Sean Paulf1d25792016-05-10 03:42:55 -0400219 if (!(region.id_set.getBits() >> layer_offset))
Sean Paul8a628b92016-04-18 15:53:36 -0400220 continue;
221
Sean Paul3960cdd2016-05-10 04:17:31 -0400222 pre_comp_regions_.emplace_back(DrmCompositionRegion{
Zach Reizner92f8e632015-10-12 17:47:13 -0700223 region.rect,
Sean Paulaa18d912016-05-12 14:28:05 -0400224 SetBitsToVector(region.id_set.getBits() >> layer_offset, comp_layers)});
Zach Reizner92f8e632015-10-12 17:47:13 -0700225 }
Zach Reizner713a6782015-07-31 15:12:44 -0700226}
227
Zach Reizner5757e822015-10-16 19:06:31 -0700228int DrmDisplayComposition::CreateAndAssignReleaseFences() {
Zach Reizner92f8e632015-10-12 17:47:13 -0700229 std::unordered_set<DrmHwcLayer *> squash_layers;
230 std::unordered_set<DrmHwcLayer *> pre_comp_layers;
231 std::unordered_set<DrmHwcLayer *> comp_layers;
232
233 for (const DrmCompositionRegion &region : squash_regions_) {
234 for (size_t source_layer_index : region.source_layers) {
235 DrmHwcLayer *source_layer = &layers_[source_layer_index];
236 squash_layers.emplace(source_layer);
237 }
238 }
239
240 for (const DrmCompositionRegion &region : pre_comp_regions_) {
241 for (size_t source_layer_index : region.source_layers) {
242 DrmHwcLayer *source_layer = &layers_[source_layer_index];
243 pre_comp_layers.emplace(source_layer);
244 squash_layers.erase(source_layer);
245 }
246 }
247
248 for (const DrmCompositionPlane &plane : composition_planes_) {
Sean Paulbbe39db2016-05-11 16:57:26 -0400249 if (plane.type() == DrmCompositionPlane::Type::kLayer) {
Sean Paulca699be2016-05-11 16:29:45 -0400250 for (auto i : plane.source_layers()) {
251 DrmHwcLayer *source_layer = &layers_[i];
252 comp_layers.emplace(source_layer);
253 pre_comp_layers.erase(source_layer);
254 }
Zach Reizner92f8e632015-10-12 17:47:13 -0700255 }
256 }
257
258 for (DrmHwcLayer *layer : squash_layers) {
Zach Reiznercb1cfc82015-11-13 16:11:37 -0800259 if (!layer->release_fence)
260 continue;
Zach Reizner92f8e632015-10-12 17:47:13 -0700261 int ret = layer->release_fence.Set(CreateNextTimelineFence());
Sean Paul8600e342017-02-28 13:25:26 -0500262 if (ret < 0) {
263 ALOGE("Failed to set the release fence (squash) %d", ret);
Zach Reizner92f8e632015-10-12 17:47:13 -0700264 return ret;
Sean Paul8600e342017-02-28 13:25:26 -0500265 }
Zach Reizner92f8e632015-10-12 17:47:13 -0700266 }
267 timeline_squash_done_ = timeline_;
268
269 for (DrmHwcLayer *layer : pre_comp_layers) {
Zach Reiznercb1cfc82015-11-13 16:11:37 -0800270 if (!layer->release_fence)
271 continue;
Zach Reizner92f8e632015-10-12 17:47:13 -0700272 int ret = layer->release_fence.Set(CreateNextTimelineFence());
273 if (ret < 0)
274 return ret;
275 }
Zach Reizner09807052015-08-13 14:53:41 -0700276 timeline_pre_comp_done_ = timeline_;
277
Zach Reizner92f8e632015-10-12 17:47:13 -0700278 for (DrmHwcLayer *layer : comp_layers) {
Zach Reiznercb1cfc82015-11-13 16:11:37 -0800279 if (!layer->release_fence)
280 continue;
Zach Reizner92f8e632015-10-12 17:47:13 -0700281 int ret = layer->release_fence.Set(CreateNextTimelineFence());
Sean Paul8600e342017-02-28 13:25:26 -0500282 if (ret < 0) {
283 ALOGE("Failed to set the release fence (comp) %d", ret);
Zach Reizner92f8e632015-10-12 17:47:13 -0700284 return ret;
Sean Paul8600e342017-02-28 13:25:26 -0500285 }
Zach Reizner09807052015-08-13 14:53:41 -0700286 }
287
Zach Reizner09807052015-08-13 14:53:41 -0700288 return 0;
Zach Reizner46ddd452015-07-30 08:10:14 -0700289}
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700290
Zach Reizner5757e822015-10-16 19:06:31 -0700291int DrmDisplayComposition::Plan(SquashState *squash,
292 std::vector<DrmPlane *> *primary_planes,
293 std::vector<DrmPlane *> *overlay_planes) {
294 if (type_ != DRM_COMPOSITION_TYPE_FRAME)
295 return 0;
296
Sean Paulaa18d912016-05-12 14:28:05 -0400297 // Used to track which layers should be sent to the planner. We exclude layers
298 // that are entirely squashed so the planner can provision a precomposition
299 // layer as appropriate (ex: if 5 layers are squashed and 1 is not, we don't
300 // want to plan a precomposition layer that will be comprised of the already
301 // squashed layers).
302 std::map<size_t, DrmHwcLayer *> to_composite;
Zach Reizner5757e822015-10-16 19:06:31 -0700303
304 bool use_squash_framebuffer = false;
305 // Used to determine which layers were entirely squashed
306 std::vector<int> layer_squash_area(layers_.size(), 0);
307 // Used to avoid rerendering regions that were squashed
308 std::vector<DrmHwcRect<int>> exclude_rects;
Sean Paulaa18d912016-05-12 14:28:05 -0400309 if (squash != NULL) {
Zach Reizner5757e822015-10-16 19:06:31 -0700310 if (geometry_changed_) {
311 squash->Init(layers_.data(), layers_.size());
312 } else {
313 std::vector<bool> changed_regions;
314 squash->GenerateHistory(layers_.data(), layers_.size(), changed_regions);
315
316 std::vector<bool> stable_regions;
317 squash->StableRegionsWithMarginalHistory(changed_regions, stable_regions);
318
319 // Only if SOME region is stable
320 use_squash_framebuffer =
321 std::find(stable_regions.begin(), stable_regions.end(), true) !=
322 stable_regions.end();
323
324 squash->RecordHistory(layers_.data(), layers_.size(), changed_regions);
325
326 // Changes in which regions are squashed triggers a rerender via
327 // squash_regions.
328 bool render_squash = squash->RecordAndCompareSquashed(stable_regions);
329
330 for (size_t region_index = 0; region_index < stable_regions.size();
331 region_index++) {
332 const SquashState::Region &region = squash->regions()[region_index];
333 if (!stable_regions[region_index])
334 continue;
335
336 exclude_rects.emplace_back(region.rect);
337
338 if (render_squash) {
339 squash_regions_.emplace_back();
340 squash_regions_.back().frame = region.rect;
341 }
342
343 int frame_area = region.rect.area();
344 // Source layers are sorted front to back i.e. top layer has lowest
345 // index.
346 for (size_t layer_index = layers_.size();
347 layer_index-- > 0; // Yes, I double checked this
348 /* See condition */) {
349 if (!region.layer_refs[layer_index])
350 continue;
351 layer_squash_area[layer_index] += frame_area;
352 if (render_squash)
353 squash_regions_.back().source_layers.push_back(layer_index);
354 }
355 }
356 }
Sean Paulaa18d912016-05-12 14:28:05 -0400357
358 for (size_t i = 0; i < layers_.size(); ++i) {
359 if (layer_squash_area[i] < layers_[i].display_frame.area())
360 to_composite.emplace(std::make_pair(i, &layers_[i]));
361 }
362 } else {
363 for (size_t i = 0; i < layers_.size(); ++i)
364 to_composite.emplace(std::make_pair(i, &layers_[i]));
Zach Reizner5757e822015-10-16 19:06:31 -0700365 }
366
Sean Paulaa18d912016-05-12 14:28:05 -0400367 int ret;
368 std::vector<DrmCompositionPlane> plan;
369 std::tie(ret, composition_planes_) =
370 planner_->ProvisionPlanes(to_composite, use_squash_framebuffer, crtc_,
371 primary_planes, overlay_planes);
372 if (ret) {
373 ALOGE("Planner failed provisioning planes ret=%d", ret);
374 return ret;
375 }
376
377 // Remove the planes we used from the pool before returning. This ensures they
378 // won't be reused by another display in the composition.
379 for (auto &i : composition_planes_) {
380 if (!i.plane())
Zach Reizner5757e822015-10-16 19:06:31 -0700381 continue;
Zach Reizner5757e822015-10-16 19:06:31 -0700382
Adrian Salido1a1cf9b2017-09-21 16:53:48 -0700383 // make sure that source layers are ordered based on zorder
384 std::sort(i.source_layers().begin(), i.source_layers().end());
385
Sean Paulaa18d912016-05-12 14:28:05 -0400386 std::vector<DrmPlane *> *container;
387 if (i.plane()->type() == DRM_PLANE_TYPE_PRIMARY)
388 container = primary_planes;
389 else
390 container = overlay_planes;
391 for (auto j = container->begin(); j != container->end(); ++j) {
392 if (*j == i.plane()) {
393 container->erase(j);
394 break;
395 }
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700396 }
397 }
Zach Reizner5757e822015-10-16 19:06:31 -0700398
Sean Paulaa18d912016-05-12 14:28:05 -0400399 return FinalizeComposition(exclude_rects.data(), exclude_rects.size());
Sean Paul4f4ef692016-05-03 16:40:59 -0700400}
401
402int DrmDisplayComposition::FinalizeComposition() {
Sean Paulaa18d912016-05-12 14:28:05 -0400403 return FinalizeComposition(NULL, 0);
404}
405
406int DrmDisplayComposition::FinalizeComposition(DrmHwcRect<int> *exclude_rects,
407 size_t num_exclude_rects) {
408 SeparateLayers(exclude_rects, num_exclude_rects);
Zach Reizner5757e822015-10-16 19:06:31 -0700409 return CreateAndAssignReleaseFences();
410}
411
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700412static const char *DrmCompositionTypeToString(DrmCompositionType type) {
413 switch (type) {
414 case DRM_COMPOSITION_TYPE_EMPTY:
415 return "EMPTY";
416 case DRM_COMPOSITION_TYPE_FRAME:
417 return "FRAME";
418 case DRM_COMPOSITION_TYPE_DPMS:
419 return "DPMS";
420 case DRM_COMPOSITION_TYPE_MODESET:
421 return "MODESET";
422 default:
423 return "<invalid>";
424 }
425}
426
427static const char *DPMSModeToString(int dpms_mode) {
428 switch (dpms_mode) {
429 case DRM_MODE_DPMS_ON:
430 return "ON";
431 case DRM_MODE_DPMS_OFF:
432 return "OFF";
433 default:
434 return "<invalid>";
435 }
436}
437
438static void DumpBuffer(const DrmHwcBuffer &buffer, std::ostringstream *out) {
439 if (!buffer) {
440 *out << "buffer=<invalid>";
441 return;
442 }
443
444 *out << "buffer[w/h/format]=";
445 *out << buffer->width << "/" << buffer->height << "/" << buffer->format;
446}
447
Sean Paul04b47ea2015-11-19 21:46:11 -0500448static void DumpTransform(uint32_t transform, std::ostringstream *out) {
449 *out << "[";
450
451 if (transform == 0)
452 *out << "IDENTITY";
453
454 bool separator = false;
455 if (transform & DrmHwcTransform::kFlipH) {
456 *out << "FLIPH";
457 separator = true;
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700458 }
Sean Paul04b47ea2015-11-19 21:46:11 -0500459 if (transform & DrmHwcTransform::kFlipV) {
460 if (separator)
461 *out << "|";
462 *out << "FLIPV";
463 separator = true;
464 }
465 if (transform & DrmHwcTransform::kRotate90) {
466 if (separator)
467 *out << "|";
468 *out << "ROTATE90";
469 separator = true;
470 }
471 if (transform & DrmHwcTransform::kRotate180) {
472 if (separator)
473 *out << "|";
474 *out << "ROTATE180";
475 separator = true;
476 }
477 if (transform & DrmHwcTransform::kRotate270) {
478 if (separator)
479 *out << "|";
480 *out << "ROTATE270";
481 separator = true;
482 }
483
484 uint32_t valid_bits = DrmHwcTransform::kFlipH | DrmHwcTransform::kFlipH |
485 DrmHwcTransform::kRotate90 |
486 DrmHwcTransform::kRotate180 |
487 DrmHwcTransform::kRotate270;
488 if (transform & ~valid_bits) {
489 if (separator)
490 *out << "|";
491 *out << "INVALID";
492 }
493 *out << "]";
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700494}
495
496static const char *BlendingToString(DrmHwcBlending blending) {
497 switch (blending) {
498 case DrmHwcBlending::kNone:
499 return "NONE";
500 case DrmHwcBlending::kPreMult:
501 return "PREMULT";
502 case DrmHwcBlending::kCoverage:
503 return "COVERAGE";
504 default:
505 return "<invalid>";
506 }
507}
508
509static void DumpRegion(const DrmCompositionRegion &region,
510 std::ostringstream *out) {
511 *out << "frame";
512 region.frame.Dump(out);
513 *out << " source_layers=(";
514
515 const std::vector<size_t> &source_layers = region.source_layers;
516 for (size_t i = 0; i < source_layers.size(); i++) {
517 *out << source_layers[i];
518 if (i < source_layers.size() - 1) {
519 *out << " ";
520 }
521 }
522
523 *out << ")";
524}
525
526void DrmDisplayComposition::Dump(std::ostringstream *out) const {
527 *out << "----DrmDisplayComposition"
528 << " crtc=" << (crtc_ ? crtc_->id() : -1)
529 << " type=" << DrmCompositionTypeToString(type_);
530
531 switch (type_) {
532 case DRM_COMPOSITION_TYPE_DPMS:
533 *out << " dpms_mode=" << DPMSModeToString(dpms_mode_);
534 break;
535 case DRM_COMPOSITION_TYPE_MODESET:
536 *out << " display_mode=" << display_mode_.h_display() << "x"
537 << display_mode_.v_display();
538 break;
539 default:
540 break;
541 }
542
543 *out << " timeline[current/squash/pre-comp/done]=" << timeline_current_ << "/"
544 << timeline_squash_done_ << "/" << timeline_pre_comp_done_ << "/"
545 << timeline_ << "\n";
546
547 *out << " Layers: count=" << layers_.size() << "\n";
548 for (size_t i = 0; i < layers_.size(); i++) {
549 const DrmHwcLayer &layer = layers_[i];
550 *out << " [" << i << "] ";
551
552 DumpBuffer(layer.buffer, out);
553
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700554 if (layer.protected_usage())
555 *out << " protected";
556
Sean Paul04b47ea2015-11-19 21:46:11 -0500557 *out << " transform=";
558 DumpTransform(layer.transform, out);
559 *out << " blending[a=" << (int)layer.alpha
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700560 << "]=" << BlendingToString(layer.blending) << " source_crop";
561 layer.source_crop.Dump(out);
562 *out << " display_frame";
563 layer.display_frame.Dump(out);
564
565 *out << "\n";
566 }
567
568 *out << " Planes: count=" << composition_planes_.size() << "\n";
569 for (size_t i = 0; i < composition_planes_.size(); i++) {
570 const DrmCompositionPlane &comp_plane = composition_planes_[i];
571 *out << " [" << i << "]"
Sean Paulca699be2016-05-11 16:29:45 -0400572 << " plane=" << (comp_plane.plane() ? comp_plane.plane()->id() : -1)
Sean Paul39b37842016-05-11 13:50:28 -0400573 << " type=";
Sean Paulca699be2016-05-11 16:29:45 -0400574 switch (comp_plane.type()) {
Sean Paulbbe39db2016-05-11 16:57:26 -0400575 case DrmCompositionPlane::Type::kDisable:
Sean Paul39b37842016-05-11 13:50:28 -0400576 *out << "DISABLE";
577 break;
Sean Paulbbe39db2016-05-11 16:57:26 -0400578 case DrmCompositionPlane::Type::kLayer:
Sean Paul39b37842016-05-11 13:50:28 -0400579 *out << "LAYER";
580 break;
Sean Paulbbe39db2016-05-11 16:57:26 -0400581 case DrmCompositionPlane::Type::kPrecomp:
Sean Paul39b37842016-05-11 13:50:28 -0400582 *out << "PRECOMP";
583 break;
Sean Paulbbe39db2016-05-11 16:57:26 -0400584 case DrmCompositionPlane::Type::kSquash:
Sean Paul39b37842016-05-11 13:50:28 -0400585 *out << "SQUASH";
586 break;
587 default:
588 *out << "<invalid>";
589 break;
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700590 }
591
Sean Paulca699be2016-05-11 16:29:45 -0400592 *out << " source_layer=";
593 for (auto i : comp_plane.source_layers()) {
594 *out << i << " ";
595 }
596 *out << "\n";
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700597 }
598
599 *out << " Squash Regions: count=" << squash_regions_.size() << "\n";
600 for (size_t i = 0; i < squash_regions_.size(); i++) {
601 *out << " [" << i << "] ";
602 DumpRegion(squash_regions_[i], out);
603 *out << "\n";
604 }
605
606 *out << " Pre-Comp Regions: count=" << pre_comp_regions_.size() << "\n";
607 for (size_t i = 0; i < pre_comp_regions_.size(); i++) {
608 *out << " [" << i << "] ";
609 DumpRegion(pre_comp_regions_[i], out);
610 *out << "\n";
611 }
612}
Sean Paul98e73c82015-06-24 14:38:49 -0700613}