blob: d5e97b4e1e5d5a668d888d1a661f59f547e4ba0b [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"
23
24#include <stdlib.h>
25
Zach Reizner92f8e632015-10-12 17:47:13 -070026#include <algorithm>
27#include <unordered_set>
28
Sean Paul98e73c82015-06-24 14:38:49 -070029#include <cutils/log.h>
30#include <sw_sync.h>
31#include <sync/sync.h>
Sean Pauldb7a17d2015-06-24 18:46:05 -070032#include <xf86drmMode.h>
Sean Paul98e73c82015-06-24 14:38:49 -070033
34namespace android {
35
Zach Reizner92f8e632015-10-12 17:47:13 -070036const size_t DrmCompositionPlane::kSourceNone;
37const size_t DrmCompositionPlane::kSourcePreComp;
38const size_t DrmCompositionPlane::kSourceSquash;
39const size_t DrmCompositionPlane::kSourceLayerMax;
Sean Paul98e73c82015-06-24 14:38:49 -070040
41DrmDisplayComposition::~DrmDisplayComposition() {
Zach Reiznerece04892015-07-17 14:13:28 -070042 if (timeline_fd_ >= 0) {
Zach Reizner92f8e632015-10-12 17:47:13 -070043 SignalCompositionDone();
Sean Paul98e73c82015-06-24 14:38:49 -070044 close(timeline_fd_);
Zach Reiznerece04892015-07-17 14:13:28 -070045 }
Sean Paul98e73c82015-06-24 14:38:49 -070046}
47
Zach Reizner09807052015-08-13 14:53:41 -070048int DrmDisplayComposition::Init(DrmResources *drm, DrmCrtc *crtc,
Sean Paulbdc67bf2015-09-21 10:04:02 -040049 Importer *importer, uint64_t frame_no) {
Sean Paul98e73c82015-06-24 14:38:49 -070050 drm_ = drm;
Zach Reizner4a253652015-09-10 18:30:54 -070051 crtc_ = crtc; // Can be NULL if we haven't modeset yet
Sean Paul98e73c82015-06-24 14:38:49 -070052 importer_ = importer;
Sean Paulbdc67bf2015-09-21 10:04:02 -040053 frame_no_ = frame_no;
Sean Paul98e73c82015-06-24 14:38:49 -070054
Zach Reizner4a253652015-09-10 18:30:54 -070055 int ret = sw_sync_timeline_create();
Sean Paul98e73c82015-06-24 14:38:49 -070056 if (ret < 0) {
57 ALOGE("Failed to create sw sync timeline %d", ret);
58 return ret;
59 }
60 timeline_fd_ = ret;
61 return 0;
62}
63
Sean Paulacb2a442015-06-24 18:43:01 -070064bool DrmDisplayComposition::validate_composition_type(DrmCompositionType des) {
65 return type_ == DRM_COMPOSITION_TYPE_EMPTY || type_ == des;
66}
67
Zach Reizner92f8e632015-10-12 17:47:13 -070068int DrmDisplayComposition::CreateNextTimelineFence() {
69 ++timeline_;
70 return sw_sync_fence_create(timeline_fd_, "hwc drm display composition fence",
71 timeline_);
72}
73
74int DrmDisplayComposition::IncreaseTimelineToPoint(int point) {
75 int timeline_increase = point - timeline_current_;
76 if (timeline_increase <= 0)
77 return 0;
78
79 int ret = sw_sync_timeline_inc(timeline_fd_, timeline_increase);
80 if (ret)
81 ALOGE("Failed to increment sync timeline %d", ret);
82 else
83 timeline_current_ = point;
84
85 return ret;
86}
87
Zach Reizner5757e822015-10-16 19:06:31 -070088int DrmDisplayComposition::SetLayers(DrmHwcLayer *layers, size_t num_layers,
89 bool geometry_changed) {
Zach Reizner92f8e632015-10-12 17:47:13 -070090 if (!validate_composition_type(DRM_COMPOSITION_TYPE_FRAME))
91 return -EINVAL;
92
Zach Reizner5757e822015-10-16 19:06:31 -070093 geometry_changed_ = geometry_changed;
94
Zach Reizner92f8e632015-10-12 17:47:13 -070095 for (size_t layer_index = 0; layer_index < num_layers; layer_index++) {
96 layers_.emplace_back(std::move(layers[layer_index]));
97 }
98
99 type_ = DRM_COMPOSITION_TYPE_FRAME;
100 return 0;
101}
102
103int DrmDisplayComposition::SetDpmsMode(uint32_t dpms_mode) {
104 if (!validate_composition_type(DRM_COMPOSITION_TYPE_DPMS))
105 return -EINVAL;
106 dpms_mode_ = dpms_mode;
107 type_ = DRM_COMPOSITION_TYPE_DPMS;
108 return 0;
109}
110
111int DrmDisplayComposition::SetDisplayMode(const DrmMode &display_mode) {
112 if (!validate_composition_type(DRM_COMPOSITION_TYPE_MODESET))
113 return -EINVAL;
114 display_mode_ = display_mode;
115 dpms_mode_ = DRM_MODE_DPMS_ON;
116 type_ = DRM_COMPOSITION_TYPE_MODESET;
117 return 0;
118}
119
120int DrmDisplayComposition::AddPlaneDisable(DrmPlane *plane) {
121 composition_planes_.emplace_back(
122 DrmCompositionPlane{plane, crtc_, DrmCompositionPlane::kSourceNone});
123 return 0;
124}
125
126static size_t CountUsablePlanes(DrmCrtc *crtc,
127 std::vector<DrmPlane *> *primary_planes,
128 std::vector<DrmPlane *> *overlay_planes) {
129 return std::count_if(
130 primary_planes->begin(), primary_planes->end(),
131 [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); }) +
132 std::count_if(
133 overlay_planes->begin(), overlay_planes->end(),
134 [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
135}
136
Zach Reizner09807052015-08-13 14:53:41 -0700137static DrmPlane *TakePlane(DrmCrtc *crtc, std::vector<DrmPlane *> *planes) {
138 for (auto iter = planes->begin(); iter != planes->end(); ++iter) {
139 if ((*iter)->GetCrtcSupported(*crtc)) {
140 DrmPlane *plane = *iter;
141 planes->erase(iter);
142 return plane;
143 }
Zach Reiznerb44fd102015-08-07 16:00:01 -0700144 }
Zach Reizner09807052015-08-13 14:53:41 -0700145 return NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700146}
147
Zach Reizner09807052015-08-13 14:53:41 -0700148static DrmPlane *TakePlane(DrmCrtc *crtc,
149 std::vector<DrmPlane *> *primary_planes,
150 std::vector<DrmPlane *> *overlay_planes) {
151 DrmPlane *plane = TakePlane(crtc, primary_planes);
152 if (plane)
153 return plane;
154 return TakePlane(crtc, overlay_planes);
155}
Zach Reizner713a6782015-07-31 15:12:44 -0700156
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700157void DrmDisplayComposition::EmplaceCompositionPlane(
158 size_t source_layer, std::vector<DrmPlane *> *primary_planes,
159 std::vector<DrmPlane *> *overlay_planes) {
160 DrmPlane *plane = TakePlane(crtc_, primary_planes, overlay_planes);
161 if (plane == NULL) {
162 ALOGE(
163 "Failed to add composition plane because there are no planes "
164 "remaining");
165 return;
166 }
167 composition_planes_.emplace_back(
168 DrmCompositionPlane{plane, crtc_, source_layer});
169}
170
Zach Reizner92f8e632015-10-12 17:47:13 -0700171static std::vector<size_t> SetBitsToVector(uint64_t in, size_t *index_map) {
172 std::vector<size_t> out;
173 size_t msb = sizeof(in) * 8 - 1;
174 uint64_t mask = (uint64_t)1 << msb;
175 for (size_t i = msb; mask != (uint64_t)0; i--, mask >>= 1)
176 if (in & mask)
177 out.push_back(index_map[i]);
178 return out;
Zach Reizner09807052015-08-13 14:53:41 -0700179}
Zach Reizner713a6782015-07-31 15:12:44 -0700180
Zach Reizner5757e822015-10-16 19:06:31 -0700181static void SeparateLayers(DrmHwcLayer *layers, size_t *used_layers,
Zach Reizner92f8e632015-10-12 17:47:13 -0700182 size_t num_used_layers,
Sean Paul0478f792016-04-18 15:53:36 -0400183 size_t *protected_layers,
184 size_t num_protected_layers,
Zach Reizner92f8e632015-10-12 17:47:13 -0700185 DrmHwcRect<int> *exclude_rects,
186 size_t num_exclude_rects,
187 std::vector<DrmCompositionRegion> &regions) {
188 if (num_used_layers > 64) {
189 ALOGE("Failed to separate layers because there are more than 64");
190 return;
191 }
Zach Reizner713a6782015-07-31 15:12:44 -0700192
Sean Paul0478f792016-04-18 15:53:36 -0400193 // Index at which the actual layers begin
194 size_t layer_offset = num_exclude_rects + num_protected_layers;
195
196 if (num_used_layers + layer_offset > 64) {
Zach Reizner92f8e632015-10-12 17:47:13 -0700197 ALOGW(
198 "Exclusion rectangles are being truncated to make the rectangle count "
199 "fit into 64");
Sean Paul0478f792016-04-18 15:53:36 -0400200 num_exclude_rects = 64 - num_used_layers - num_protected_layers;
Zach Reizner92f8e632015-10-12 17:47:13 -0700201 }
Zach Reizner713a6782015-07-31 15:12:44 -0700202
Zach Reizner92f8e632015-10-12 17:47:13 -0700203 // We inject all the exclude rects into the rects list. Any resulting rect
Sean Paul0478f792016-04-18 15:53:36 -0400204 // that includes ANY of the first num_exclude_rects is rejected. After the
205 // exclude rects, we add the protected layers. The rects that intersect with
206 // the protected layer will be inspected and only those which are above the
207 // protected layer will be included in the composition regions.
208 std::vector<DrmHwcRect<int>> layer_rects(num_used_layers + layer_offset);
Zach Reizner92f8e632015-10-12 17:47:13 -0700209 std::copy(exclude_rects, exclude_rects + num_exclude_rects,
210 layer_rects.begin());
211 std::transform(
Sean Paul0478f792016-04-18 15:53:36 -0400212 protected_layers, protected_layers + num_protected_layers,
Zach Reizner92f8e632015-10-12 17:47:13 -0700213 layer_rects.begin() + num_exclude_rects,
214 [=](size_t layer_index) { return layers[layer_index].display_frame; });
Sean Paul0478f792016-04-18 15:53:36 -0400215 std::transform(
216 used_layers, used_layers + num_used_layers,
217 layer_rects.begin() + layer_offset,
218 [=](size_t layer_index) { return layers[layer_index].display_frame; });
Zach Reizner92f8e632015-10-12 17:47:13 -0700219
Haixia Shiaa2f4a52015-11-02 10:54:29 -0800220 std::vector<separate_rects::RectSet<uint64_t, int>> separate_regions;
221 separate_rects::separate_rects_64(layer_rects, &separate_regions);
Zach Reizner92f8e632015-10-12 17:47:13 -0700222 uint64_t exclude_mask = ((uint64_t)1 << num_exclude_rects) - 1;
Sean Paul0478f792016-04-18 15:53:36 -0400223 uint64_t protected_mask = (((uint64_t)1 << num_protected_layers) - 1) <<
224 num_exclude_rects;
Zach Reizner92f8e632015-10-12 17:47:13 -0700225
Haixia Shiaa2f4a52015-11-02 10:54:29 -0800226 for (separate_rects::RectSet<uint64_t, int> &region : separate_regions) {
Zach Reizner92f8e632015-10-12 17:47:13 -0700227 if (region.id_set.getBits() & exclude_mask)
228 continue;
Sean Paul0478f792016-04-18 15:53:36 -0400229
230 // If a rect intersects a protected layer, we need to remove the layers
231 // from the composition region which appear *below* the protected layer.
232 // This effectively punches a hole through the composition layer such
233 // that the protected layer can be placed below the composition and not
234 // be occluded by things like the background.
235 uint64_t protected_intersect = region.id_set.getBits() & protected_mask;
236 for (size_t i = 0; protected_intersect && i < num_protected_layers; ++i) {
237 // Only exclude layers if they intersect this particular protected layer
238 if (!(protected_intersect & (1 << (i + num_exclude_rects))))
239 continue;
240
241 region.id_set.subtract(layer_offset, layer_offset + protected_layers[i]);
242 }
243 if (region.id_set.isEmpty())
244 continue;
245
Zach Reizner92f8e632015-10-12 17:47:13 -0700246 regions.emplace_back(DrmCompositionRegion{
247 region.rect,
Sean Paul0478f792016-04-18 15:53:36 -0400248 SetBitsToVector(region.id_set.getBits() >> layer_offset,
Zach Reizner92f8e632015-10-12 17:47:13 -0700249 used_layers)});
250 }
Zach Reizner713a6782015-07-31 15:12:44 -0700251}
252
Zach Reizner5757e822015-10-16 19:06:31 -0700253int DrmDisplayComposition::CreateAndAssignReleaseFences() {
Zach Reizner92f8e632015-10-12 17:47:13 -0700254 std::unordered_set<DrmHwcLayer *> squash_layers;
255 std::unordered_set<DrmHwcLayer *> pre_comp_layers;
256 std::unordered_set<DrmHwcLayer *> comp_layers;
257
258 for (const DrmCompositionRegion &region : squash_regions_) {
259 for (size_t source_layer_index : region.source_layers) {
260 DrmHwcLayer *source_layer = &layers_[source_layer_index];
261 squash_layers.emplace(source_layer);
262 }
263 }
264
265 for (const DrmCompositionRegion &region : pre_comp_regions_) {
266 for (size_t source_layer_index : region.source_layers) {
267 DrmHwcLayer *source_layer = &layers_[source_layer_index];
268 pre_comp_layers.emplace(source_layer);
269 squash_layers.erase(source_layer);
270 }
271 }
272
273 for (const DrmCompositionPlane &plane : composition_planes_) {
274 if (plane.source_layer <= DrmCompositionPlane::kSourceLayerMax) {
275 DrmHwcLayer *source_layer = &layers_[plane.source_layer];
276 comp_layers.emplace(source_layer);
277 pre_comp_layers.erase(source_layer);
278 }
279 }
280
281 for (DrmHwcLayer *layer : squash_layers) {
Zach Reiznercb1cfc82015-11-13 16:11:37 -0800282 if (!layer->release_fence)
283 continue;
Zach Reizner92f8e632015-10-12 17:47:13 -0700284 int ret = layer->release_fence.Set(CreateNextTimelineFence());
285 if (ret < 0)
286 return ret;
287 }
288 timeline_squash_done_ = timeline_;
289
290 for (DrmHwcLayer *layer : pre_comp_layers) {
Zach Reiznercb1cfc82015-11-13 16:11:37 -0800291 if (!layer->release_fence)
292 continue;
Zach Reizner92f8e632015-10-12 17:47:13 -0700293 int ret = layer->release_fence.Set(CreateNextTimelineFence());
294 if (ret < 0)
295 return ret;
296 }
Zach Reizner09807052015-08-13 14:53:41 -0700297 timeline_pre_comp_done_ = timeline_;
298
Zach Reizner92f8e632015-10-12 17:47:13 -0700299 for (DrmHwcLayer *layer : comp_layers) {
Zach Reiznercb1cfc82015-11-13 16:11:37 -0800300 if (!layer->release_fence)
301 continue;
Zach Reizner92f8e632015-10-12 17:47:13 -0700302 int ret = layer->release_fence.Set(CreateNextTimelineFence());
303 if (ret < 0)
304 return ret;
Zach Reizner09807052015-08-13 14:53:41 -0700305 }
306
Zach Reizner09807052015-08-13 14:53:41 -0700307 return 0;
Zach Reizner46ddd452015-07-30 08:10:14 -0700308}
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700309
Zach Reizner5757e822015-10-16 19:06:31 -0700310int DrmDisplayComposition::Plan(SquashState *squash,
311 std::vector<DrmPlane *> *primary_planes,
312 std::vector<DrmPlane *> *overlay_planes) {
313 if (type_ != DRM_COMPOSITION_TYPE_FRAME)
314 return 0;
315
316 size_t planes_can_use =
317 CountUsablePlanes(crtc_, primary_planes, overlay_planes);
318 if (planes_can_use == 0) {
319 ALOGE("Display %d has no usable planes", crtc_->display());
320 return -ENODEV;
321 }
322
323 bool use_squash_framebuffer = false;
324 // Used to determine which layers were entirely squashed
325 std::vector<int> layer_squash_area(layers_.size(), 0);
326 // Used to avoid rerendering regions that were squashed
327 std::vector<DrmHwcRect<int>> exclude_rects;
328 if (squash != NULL && planes_can_use >= 3) {
329 if (geometry_changed_) {
330 squash->Init(layers_.data(), layers_.size());
331 } else {
332 std::vector<bool> changed_regions;
333 squash->GenerateHistory(layers_.data(), layers_.size(), changed_regions);
334
335 std::vector<bool> stable_regions;
336 squash->StableRegionsWithMarginalHistory(changed_regions, stable_regions);
337
338 // Only if SOME region is stable
339 use_squash_framebuffer =
340 std::find(stable_regions.begin(), stable_regions.end(), true) !=
341 stable_regions.end();
342
343 squash->RecordHistory(layers_.data(), layers_.size(), changed_regions);
344
345 // Changes in which regions are squashed triggers a rerender via
346 // squash_regions.
347 bool render_squash = squash->RecordAndCompareSquashed(stable_regions);
348
349 for (size_t region_index = 0; region_index < stable_regions.size();
350 region_index++) {
351 const SquashState::Region &region = squash->regions()[region_index];
352 if (!stable_regions[region_index])
353 continue;
354
355 exclude_rects.emplace_back(region.rect);
356
357 if (render_squash) {
358 squash_regions_.emplace_back();
359 squash_regions_.back().frame = region.rect;
360 }
361
362 int frame_area = region.rect.area();
363 // Source layers are sorted front to back i.e. top layer has lowest
364 // index.
365 for (size_t layer_index = layers_.size();
366 layer_index-- > 0; // Yes, I double checked this
367 /* See condition */) {
368 if (!region.layer_refs[layer_index])
369 continue;
370 layer_squash_area[layer_index] += frame_area;
371 if (render_squash)
372 squash_regions_.back().source_layers.push_back(layer_index);
373 }
374 }
375 }
376 }
377
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700378 // All protected layers get first usage of planes
Zach Reizner5757e822015-10-16 19:06:31 -0700379 std::vector<size_t> layers_remaining;
Sean Paul0478f792016-04-18 15:53:36 -0400380 std::vector<size_t> protected_layers;
Zach Reizner5757e822015-10-16 19:06:31 -0700381 for (size_t layer_index = 0; layer_index < layers_.size(); layer_index++) {
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700382 if (!layers_[layer_index].protected_usage() || planes_can_use == 0) {
383 layers_remaining.push_back(layer_index);
Zach Reizner5757e822015-10-16 19:06:31 -0700384 continue;
385 }
Sean Paul0478f792016-04-18 15:53:36 -0400386 protected_layers.push_back(layer_index);
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700387 planes_can_use--;
Zach Reizner5757e822015-10-16 19:06:31 -0700388 }
389
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700390 if (planes_can_use == 0 && layers_remaining.size() > 0) {
Sean Paul0478f792016-04-18 15:53:36 -0400391 for(auto i : protected_layers)
392 EmplaceCompositionPlane(i, primary_planes, overlay_planes);
393
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700394 ALOGE("Protected layers consumed all hardware planes");
395 return CreateAndAssignReleaseFences();
396 }
397
398 std::vector<size_t> layers_remaining_if_squash;
399 for (size_t layer_index : layers_remaining) {
400 if (layer_squash_area[layer_index] <
401 layers_[layer_index].display_frame.area())
402 layers_remaining_if_squash.push_back(layer_index);
403 }
404
405 if (use_squash_framebuffer) {
406 if (planes_can_use > 1 || layers_remaining_if_squash.size() == 0) {
407 layers_remaining = std::move(layers_remaining_if_squash);
408 planes_can_use--; // Reserve plane for squashing
409 } else {
410 use_squash_framebuffer = false; // The squash buffer is still rendered
411 }
412 }
Zach Reizner5757e822015-10-16 19:06:31 -0700413
414 if (layers_remaining.size() > planes_can_use)
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700415 planes_can_use--; // Reserve one for pre-compositing
Zach Reizner5757e822015-10-16 19:06:31 -0700416
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700417 // Whatever planes that are not reserved get assigned a layer
Sean Paul0478f792016-04-18 15:53:36 -0400418 size_t last_hw_comp_layer = 0;
419 size_t protected_idx = 0;
420 while(last_hw_comp_layer < layers_remaining.size() && planes_can_use > 0) {
421 size_t idx = layers_remaining[last_hw_comp_layer];
422
423 // Put the protected layers into the composition at the right place. We've
424 // already reserved them by decrementing planes_can_use, so no need to do
425 // that again.
426 if (protected_idx < protected_layers.size() &&
427 idx > protected_layers[protected_idx]) {
428 EmplaceCompositionPlane(protected_layers[protected_idx], primary_planes,
429 overlay_planes);
430 protected_idx++;
431 continue;
432 }
433
434 EmplaceCompositionPlane(layers_remaining[last_hw_comp_layer],
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700435 primary_planes, overlay_planes);
Sean Paul0478f792016-04-18 15:53:36 -0400436 last_hw_comp_layer++;
437 planes_can_use--;
Zach Reizner5757e822015-10-16 19:06:31 -0700438 }
439
440 layers_remaining.erase(layers_remaining.begin(),
Sean Paul0478f792016-04-18 15:53:36 -0400441 layers_remaining.begin() + last_hw_comp_layer);
442
443 // Enqueue the rest of the protected layers (if any) between the hw composited
444 // overlay layers and the squash/precomp layers.
445 for(int i = protected_idx; i < protected_layers.size(); ++i)
446 EmplaceCompositionPlane(protected_layers[i], primary_planes,
447 overlay_planes);
Zach Reizner5757e822015-10-16 19:06:31 -0700448
449 if (layers_remaining.size() > 0) {
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700450 EmplaceCompositionPlane(DrmCompositionPlane::kSourcePreComp, primary_planes,
451 overlay_planes);
Zach Reizner5757e822015-10-16 19:06:31 -0700452 SeparateLayers(layers_.data(), layers_remaining.data(),
Sean Paul0478f792016-04-18 15:53:36 -0400453 layers_remaining.size(), protected_layers.data(),
454 protected_layers.size(), exclude_rects.data(),
Zach Reizner5757e822015-10-16 19:06:31 -0700455 exclude_rects.size(), pre_comp_regions_);
456 }
457
458 if (use_squash_framebuffer) {
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700459 EmplaceCompositionPlane(DrmCompositionPlane::kSourceSquash, primary_planes,
460 overlay_planes);
Zach Reizner5757e822015-10-16 19:06:31 -0700461 }
462
463 return CreateAndAssignReleaseFences();
464}
465
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700466static const char *DrmCompositionTypeToString(DrmCompositionType type) {
467 switch (type) {
468 case DRM_COMPOSITION_TYPE_EMPTY:
469 return "EMPTY";
470 case DRM_COMPOSITION_TYPE_FRAME:
471 return "FRAME";
472 case DRM_COMPOSITION_TYPE_DPMS:
473 return "DPMS";
474 case DRM_COMPOSITION_TYPE_MODESET:
475 return "MODESET";
476 default:
477 return "<invalid>";
478 }
479}
480
481static const char *DPMSModeToString(int dpms_mode) {
482 switch (dpms_mode) {
483 case DRM_MODE_DPMS_ON:
484 return "ON";
485 case DRM_MODE_DPMS_OFF:
486 return "OFF";
487 default:
488 return "<invalid>";
489 }
490}
491
492static void DumpBuffer(const DrmHwcBuffer &buffer, std::ostringstream *out) {
493 if (!buffer) {
494 *out << "buffer=<invalid>";
495 return;
496 }
497
498 *out << "buffer[w/h/format]=";
499 *out << buffer->width << "/" << buffer->height << "/" << buffer->format;
500}
501
Sean Paul04b47ea2015-11-19 21:46:11 -0500502static void DumpTransform(uint32_t transform, std::ostringstream *out) {
503 *out << "[";
504
505 if (transform == 0)
506 *out << "IDENTITY";
507
508 bool separator = false;
509 if (transform & DrmHwcTransform::kFlipH) {
510 *out << "FLIPH";
511 separator = true;
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700512 }
Sean Paul04b47ea2015-11-19 21:46:11 -0500513 if (transform & DrmHwcTransform::kFlipV) {
514 if (separator)
515 *out << "|";
516 *out << "FLIPV";
517 separator = true;
518 }
519 if (transform & DrmHwcTransform::kRotate90) {
520 if (separator)
521 *out << "|";
522 *out << "ROTATE90";
523 separator = true;
524 }
525 if (transform & DrmHwcTransform::kRotate180) {
526 if (separator)
527 *out << "|";
528 *out << "ROTATE180";
529 separator = true;
530 }
531 if (transform & DrmHwcTransform::kRotate270) {
532 if (separator)
533 *out << "|";
534 *out << "ROTATE270";
535 separator = true;
536 }
537
538 uint32_t valid_bits = DrmHwcTransform::kFlipH | DrmHwcTransform::kFlipH |
539 DrmHwcTransform::kRotate90 |
540 DrmHwcTransform::kRotate180 |
541 DrmHwcTransform::kRotate270;
542 if (transform & ~valid_bits) {
543 if (separator)
544 *out << "|";
545 *out << "INVALID";
546 }
547 *out << "]";
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700548}
549
550static const char *BlendingToString(DrmHwcBlending blending) {
551 switch (blending) {
552 case DrmHwcBlending::kNone:
553 return "NONE";
554 case DrmHwcBlending::kPreMult:
555 return "PREMULT";
556 case DrmHwcBlending::kCoverage:
557 return "COVERAGE";
558 default:
559 return "<invalid>";
560 }
561}
562
563static void DumpRegion(const DrmCompositionRegion &region,
564 std::ostringstream *out) {
565 *out << "frame";
566 region.frame.Dump(out);
567 *out << " source_layers=(";
568
569 const std::vector<size_t> &source_layers = region.source_layers;
570 for (size_t i = 0; i < source_layers.size(); i++) {
571 *out << source_layers[i];
572 if (i < source_layers.size() - 1) {
573 *out << " ";
574 }
575 }
576
577 *out << ")";
578}
579
580void DrmDisplayComposition::Dump(std::ostringstream *out) const {
581 *out << "----DrmDisplayComposition"
582 << " crtc=" << (crtc_ ? crtc_->id() : -1)
583 << " type=" << DrmCompositionTypeToString(type_);
584
585 switch (type_) {
586 case DRM_COMPOSITION_TYPE_DPMS:
587 *out << " dpms_mode=" << DPMSModeToString(dpms_mode_);
588 break;
589 case DRM_COMPOSITION_TYPE_MODESET:
590 *out << " display_mode=" << display_mode_.h_display() << "x"
591 << display_mode_.v_display();
592 break;
593 default:
594 break;
595 }
596
597 *out << " timeline[current/squash/pre-comp/done]=" << timeline_current_ << "/"
598 << timeline_squash_done_ << "/" << timeline_pre_comp_done_ << "/"
599 << timeline_ << "\n";
600
601 *out << " Layers: count=" << layers_.size() << "\n";
602 for (size_t i = 0; i < layers_.size(); i++) {
603 const DrmHwcLayer &layer = layers_[i];
604 *out << " [" << i << "] ";
605
606 DumpBuffer(layer.buffer, out);
607
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700608 if (layer.protected_usage())
609 *out << " protected";
610
Sean Paul04b47ea2015-11-19 21:46:11 -0500611 *out << " transform=";
612 DumpTransform(layer.transform, out);
613 *out << " blending[a=" << (int)layer.alpha
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700614 << "]=" << BlendingToString(layer.blending) << " source_crop";
615 layer.source_crop.Dump(out);
616 *out << " display_frame";
617 layer.display_frame.Dump(out);
618
619 *out << "\n";
620 }
621
622 *out << " Planes: count=" << composition_planes_.size() << "\n";
623 for (size_t i = 0; i < composition_planes_.size(); i++) {
624 const DrmCompositionPlane &comp_plane = composition_planes_[i];
625 *out << " [" << i << "]"
626 << " plane=" << (comp_plane.plane ? comp_plane.plane->id() : -1)
627 << " source_layer=";
628 if (comp_plane.source_layer <= DrmCompositionPlane::kSourceLayerMax) {
629 *out << comp_plane.source_layer;
630 } else {
631 switch (comp_plane.source_layer) {
632 case DrmCompositionPlane::kSourceNone:
633 *out << "NONE";
634 break;
635 case DrmCompositionPlane::kSourcePreComp:
636 *out << "PRECOMP";
637 break;
638 case DrmCompositionPlane::kSourceSquash:
639 *out << "SQUASH";
640 break;
641 default:
642 *out << "<invalid>";
643 break;
644 }
645 }
646
647 *out << "\n";
648 }
649
650 *out << " Squash Regions: count=" << squash_regions_.size() << "\n";
651 for (size_t i = 0; i < squash_regions_.size(); i++) {
652 *out << " [" << i << "] ";
653 DumpRegion(squash_regions_[i], out);
654 *out << "\n";
655 }
656
657 *out << " Pre-Comp Regions: count=" << pre_comp_regions_.size() << "\n";
658 for (size_t i = 0; i < pre_comp_regions_.size(); i++) {
659 *out << " [" << i << "] ";
660 DumpRegion(pre_comp_regions_[i], out);
661 *out << "\n";
662 }
663}
Sean Paul98e73c82015-06-24 14:38:49 -0700664}