blob: 2c5ef098cbc6c1eaac879faaacd49cc5043e6f51 [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 Paul8a628b92016-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 Paul8a628b92016-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 Paul8a628b92016-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 Paul8a628b92016-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 Paul8a628b92016-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 Paul8a628b92016-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 Paul8a628b92016-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 Paul8a628b92016-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
Sean Paulf1d25792016-05-10 03:42:55 -0400241 for (size_t j = 0; j < num_used_layers; ++j) {
242 if (used_layers[j] < protected_layers[i])
243 region.id_set.subtract(j + layer_offset);
244 }
Sean Paul8a628b92016-04-18 15:53:36 -0400245 }
Sean Paulf1d25792016-05-10 03:42:55 -0400246 if (!(region.id_set.getBits() >> layer_offset))
Sean Paul8a628b92016-04-18 15:53:36 -0400247 continue;
248
Zach Reizner92f8e632015-10-12 17:47:13 -0700249 regions.emplace_back(DrmCompositionRegion{
250 region.rect,
Sean Paulf1d25792016-05-10 03:42:55 -0400251 SetBitsToVector(region.id_set.getBits() >> layer_offset, used_layers)});
Zach Reizner92f8e632015-10-12 17:47:13 -0700252 }
Zach Reizner713a6782015-07-31 15:12:44 -0700253}
254
Zach Reizner5757e822015-10-16 19:06:31 -0700255int DrmDisplayComposition::CreateAndAssignReleaseFences() {
Zach Reizner92f8e632015-10-12 17:47:13 -0700256 std::unordered_set<DrmHwcLayer *> squash_layers;
257 std::unordered_set<DrmHwcLayer *> pre_comp_layers;
258 std::unordered_set<DrmHwcLayer *> comp_layers;
259
260 for (const DrmCompositionRegion &region : squash_regions_) {
261 for (size_t source_layer_index : region.source_layers) {
262 DrmHwcLayer *source_layer = &layers_[source_layer_index];
263 squash_layers.emplace(source_layer);
264 }
265 }
266
267 for (const DrmCompositionRegion &region : pre_comp_regions_) {
268 for (size_t source_layer_index : region.source_layers) {
269 DrmHwcLayer *source_layer = &layers_[source_layer_index];
270 pre_comp_layers.emplace(source_layer);
271 squash_layers.erase(source_layer);
272 }
273 }
274
275 for (const DrmCompositionPlane &plane : composition_planes_) {
276 if (plane.source_layer <= DrmCompositionPlane::kSourceLayerMax) {
277 DrmHwcLayer *source_layer = &layers_[plane.source_layer];
278 comp_layers.emplace(source_layer);
279 pre_comp_layers.erase(source_layer);
280 }
281 }
282
283 for (DrmHwcLayer *layer : squash_layers) {
Zach Reiznercb1cfc82015-11-13 16:11:37 -0800284 if (!layer->release_fence)
285 continue;
Zach Reizner92f8e632015-10-12 17:47:13 -0700286 int ret = layer->release_fence.Set(CreateNextTimelineFence());
287 if (ret < 0)
288 return ret;
289 }
290 timeline_squash_done_ = timeline_;
291
292 for (DrmHwcLayer *layer : pre_comp_layers) {
Zach Reiznercb1cfc82015-11-13 16:11:37 -0800293 if (!layer->release_fence)
294 continue;
Zach Reizner92f8e632015-10-12 17:47:13 -0700295 int ret = layer->release_fence.Set(CreateNextTimelineFence());
296 if (ret < 0)
297 return ret;
298 }
Zach Reizner09807052015-08-13 14:53:41 -0700299 timeline_pre_comp_done_ = timeline_;
300
Zach Reizner92f8e632015-10-12 17:47:13 -0700301 for (DrmHwcLayer *layer : comp_layers) {
Zach Reiznercb1cfc82015-11-13 16:11:37 -0800302 if (!layer->release_fence)
303 continue;
Zach Reizner92f8e632015-10-12 17:47:13 -0700304 int ret = layer->release_fence.Set(CreateNextTimelineFence());
305 if (ret < 0)
306 return ret;
Zach Reizner09807052015-08-13 14:53:41 -0700307 }
308
Zach Reizner09807052015-08-13 14:53:41 -0700309 return 0;
Zach Reizner46ddd452015-07-30 08:10:14 -0700310}
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700311
Zach Reizner5757e822015-10-16 19:06:31 -0700312int DrmDisplayComposition::Plan(SquashState *squash,
313 std::vector<DrmPlane *> *primary_planes,
314 std::vector<DrmPlane *> *overlay_planes) {
315 if (type_ != DRM_COMPOSITION_TYPE_FRAME)
316 return 0;
317
318 size_t planes_can_use =
319 CountUsablePlanes(crtc_, primary_planes, overlay_planes);
320 if (planes_can_use == 0) {
321 ALOGE("Display %d has no usable planes", crtc_->display());
322 return -ENODEV;
323 }
324
325 bool use_squash_framebuffer = false;
326 // Used to determine which layers were entirely squashed
327 std::vector<int> layer_squash_area(layers_.size(), 0);
328 // Used to avoid rerendering regions that were squashed
329 std::vector<DrmHwcRect<int>> exclude_rects;
330 if (squash != NULL && planes_can_use >= 3) {
331 if (geometry_changed_) {
332 squash->Init(layers_.data(), layers_.size());
333 } else {
334 std::vector<bool> changed_regions;
335 squash->GenerateHistory(layers_.data(), layers_.size(), changed_regions);
336
337 std::vector<bool> stable_regions;
338 squash->StableRegionsWithMarginalHistory(changed_regions, stable_regions);
339
340 // Only if SOME region is stable
341 use_squash_framebuffer =
342 std::find(stable_regions.begin(), stable_regions.end(), true) !=
343 stable_regions.end();
344
345 squash->RecordHistory(layers_.data(), layers_.size(), changed_regions);
346
347 // Changes in which regions are squashed triggers a rerender via
348 // squash_regions.
349 bool render_squash = squash->RecordAndCompareSquashed(stable_regions);
350
351 for (size_t region_index = 0; region_index < stable_regions.size();
352 region_index++) {
353 const SquashState::Region &region = squash->regions()[region_index];
354 if (!stable_regions[region_index])
355 continue;
356
357 exclude_rects.emplace_back(region.rect);
358
359 if (render_squash) {
360 squash_regions_.emplace_back();
361 squash_regions_.back().frame = region.rect;
362 }
363
364 int frame_area = region.rect.area();
365 // Source layers are sorted front to back i.e. top layer has lowest
366 // index.
367 for (size_t layer_index = layers_.size();
368 layer_index-- > 0; // Yes, I double checked this
369 /* See condition */) {
370 if (!region.layer_refs[layer_index])
371 continue;
372 layer_squash_area[layer_index] += frame_area;
373 if (render_squash)
374 squash_regions_.back().source_layers.push_back(layer_index);
375 }
376 }
377 }
378 }
379
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700380 // All protected layers get first usage of planes
Zach Reizner5757e822015-10-16 19:06:31 -0700381 std::vector<size_t> layers_remaining;
Sean Paul8a628b92016-04-18 15:53:36 -0400382 std::vector<size_t> protected_layers;
Zach Reizner5757e822015-10-16 19:06:31 -0700383 for (size_t layer_index = 0; layer_index < layers_.size(); layer_index++) {
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700384 if (!layers_[layer_index].protected_usage() || planes_can_use == 0) {
385 layers_remaining.push_back(layer_index);
Zach Reizner5757e822015-10-16 19:06:31 -0700386 continue;
387 }
Sean Paul8a628b92016-04-18 15:53:36 -0400388 protected_layers.push_back(layer_index);
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700389 planes_can_use--;
Zach Reizner5757e822015-10-16 19:06:31 -0700390 }
391
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700392 if (planes_can_use == 0 && layers_remaining.size() > 0) {
Sean Paul8a628b92016-04-18 15:53:36 -0400393 for(auto i : protected_layers)
394 EmplaceCompositionPlane(i, primary_planes, overlay_planes);
395
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700396 ALOGE("Protected layers consumed all hardware planes");
397 return CreateAndAssignReleaseFences();
398 }
399
400 std::vector<size_t> layers_remaining_if_squash;
401 for (size_t layer_index : layers_remaining) {
402 if (layer_squash_area[layer_index] <
403 layers_[layer_index].display_frame.area())
404 layers_remaining_if_squash.push_back(layer_index);
405 }
406
407 if (use_squash_framebuffer) {
408 if (planes_can_use > 1 || layers_remaining_if_squash.size() == 0) {
409 layers_remaining = std::move(layers_remaining_if_squash);
410 planes_can_use--; // Reserve plane for squashing
411 } else {
412 use_squash_framebuffer = false; // The squash buffer is still rendered
413 }
414 }
Zach Reizner5757e822015-10-16 19:06:31 -0700415
416 if (layers_remaining.size() > planes_can_use)
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700417 planes_can_use--; // Reserve one for pre-compositing
Zach Reizner5757e822015-10-16 19:06:31 -0700418
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700419 // Whatever planes that are not reserved get assigned a layer
Sean Paul8a628b92016-04-18 15:53:36 -0400420 size_t last_hw_comp_layer = 0;
421 size_t protected_idx = 0;
422 while(last_hw_comp_layer < layers_remaining.size() && planes_can_use > 0) {
423 size_t idx = layers_remaining[last_hw_comp_layer];
424
425 // Put the protected layers into the composition at the right place. We've
426 // already reserved them by decrementing planes_can_use, so no need to do
427 // that again.
428 if (protected_idx < protected_layers.size() &&
429 idx > protected_layers[protected_idx]) {
430 EmplaceCompositionPlane(protected_layers[protected_idx], primary_planes,
431 overlay_planes);
432 protected_idx++;
433 continue;
434 }
435
436 EmplaceCompositionPlane(layers_remaining[last_hw_comp_layer],
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700437 primary_planes, overlay_planes);
Sean Paul8a628b92016-04-18 15:53:36 -0400438 last_hw_comp_layer++;
439 planes_can_use--;
Zach Reizner5757e822015-10-16 19:06:31 -0700440 }
441
442 layers_remaining.erase(layers_remaining.begin(),
Sean Paul8a628b92016-04-18 15:53:36 -0400443 layers_remaining.begin() + last_hw_comp_layer);
444
445 // Enqueue the rest of the protected layers (if any) between the hw composited
446 // overlay layers and the squash/precomp layers.
447 for(int i = protected_idx; i < protected_layers.size(); ++i)
448 EmplaceCompositionPlane(protected_layers[i], primary_planes,
449 overlay_planes);
Zach Reizner5757e822015-10-16 19:06:31 -0700450
451 if (layers_remaining.size() > 0) {
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700452 EmplaceCompositionPlane(DrmCompositionPlane::kSourcePreComp, primary_planes,
453 overlay_planes);
Zach Reizner5757e822015-10-16 19:06:31 -0700454 SeparateLayers(layers_.data(), layers_remaining.data(),
Sean Paul8a628b92016-04-18 15:53:36 -0400455 layers_remaining.size(), protected_layers.data(),
456 protected_layers.size(), exclude_rects.data(),
Zach Reizner5757e822015-10-16 19:06:31 -0700457 exclude_rects.size(), pre_comp_regions_);
458 }
459
460 if (use_squash_framebuffer) {
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700461 EmplaceCompositionPlane(DrmCompositionPlane::kSourceSquash, primary_planes,
462 overlay_planes);
Zach Reizner5757e822015-10-16 19:06:31 -0700463 }
464
465 return CreateAndAssignReleaseFences();
466}
467
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700468static const char *DrmCompositionTypeToString(DrmCompositionType type) {
469 switch (type) {
470 case DRM_COMPOSITION_TYPE_EMPTY:
471 return "EMPTY";
472 case DRM_COMPOSITION_TYPE_FRAME:
473 return "FRAME";
474 case DRM_COMPOSITION_TYPE_DPMS:
475 return "DPMS";
476 case DRM_COMPOSITION_TYPE_MODESET:
477 return "MODESET";
478 default:
479 return "<invalid>";
480 }
481}
482
483static const char *DPMSModeToString(int dpms_mode) {
484 switch (dpms_mode) {
485 case DRM_MODE_DPMS_ON:
486 return "ON";
487 case DRM_MODE_DPMS_OFF:
488 return "OFF";
489 default:
490 return "<invalid>";
491 }
492}
493
494static void DumpBuffer(const DrmHwcBuffer &buffer, std::ostringstream *out) {
495 if (!buffer) {
496 *out << "buffer=<invalid>";
497 return;
498 }
499
500 *out << "buffer[w/h/format]=";
501 *out << buffer->width << "/" << buffer->height << "/" << buffer->format;
502}
503
Sean Paul04b47ea2015-11-19 21:46:11 -0500504static void DumpTransform(uint32_t transform, std::ostringstream *out) {
505 *out << "[";
506
507 if (transform == 0)
508 *out << "IDENTITY";
509
510 bool separator = false;
511 if (transform & DrmHwcTransform::kFlipH) {
512 *out << "FLIPH";
513 separator = true;
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700514 }
Sean Paul04b47ea2015-11-19 21:46:11 -0500515 if (transform & DrmHwcTransform::kFlipV) {
516 if (separator)
517 *out << "|";
518 *out << "FLIPV";
519 separator = true;
520 }
521 if (transform & DrmHwcTransform::kRotate90) {
522 if (separator)
523 *out << "|";
524 *out << "ROTATE90";
525 separator = true;
526 }
527 if (transform & DrmHwcTransform::kRotate180) {
528 if (separator)
529 *out << "|";
530 *out << "ROTATE180";
531 separator = true;
532 }
533 if (transform & DrmHwcTransform::kRotate270) {
534 if (separator)
535 *out << "|";
536 *out << "ROTATE270";
537 separator = true;
538 }
539
540 uint32_t valid_bits = DrmHwcTransform::kFlipH | DrmHwcTransform::kFlipH |
541 DrmHwcTransform::kRotate90 |
542 DrmHwcTransform::kRotate180 |
543 DrmHwcTransform::kRotate270;
544 if (transform & ~valid_bits) {
545 if (separator)
546 *out << "|";
547 *out << "INVALID";
548 }
549 *out << "]";
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700550}
551
552static const char *BlendingToString(DrmHwcBlending blending) {
553 switch (blending) {
554 case DrmHwcBlending::kNone:
555 return "NONE";
556 case DrmHwcBlending::kPreMult:
557 return "PREMULT";
558 case DrmHwcBlending::kCoverage:
559 return "COVERAGE";
560 default:
561 return "<invalid>";
562 }
563}
564
565static void DumpRegion(const DrmCompositionRegion &region,
566 std::ostringstream *out) {
567 *out << "frame";
568 region.frame.Dump(out);
569 *out << " source_layers=(";
570
571 const std::vector<size_t> &source_layers = region.source_layers;
572 for (size_t i = 0; i < source_layers.size(); i++) {
573 *out << source_layers[i];
574 if (i < source_layers.size() - 1) {
575 *out << " ";
576 }
577 }
578
579 *out << ")";
580}
581
582void DrmDisplayComposition::Dump(std::ostringstream *out) const {
583 *out << "----DrmDisplayComposition"
584 << " crtc=" << (crtc_ ? crtc_->id() : -1)
585 << " type=" << DrmCompositionTypeToString(type_);
586
587 switch (type_) {
588 case DRM_COMPOSITION_TYPE_DPMS:
589 *out << " dpms_mode=" << DPMSModeToString(dpms_mode_);
590 break;
591 case DRM_COMPOSITION_TYPE_MODESET:
592 *out << " display_mode=" << display_mode_.h_display() << "x"
593 << display_mode_.v_display();
594 break;
595 default:
596 break;
597 }
598
599 *out << " timeline[current/squash/pre-comp/done]=" << timeline_current_ << "/"
600 << timeline_squash_done_ << "/" << timeline_pre_comp_done_ << "/"
601 << timeline_ << "\n";
602
603 *out << " Layers: count=" << layers_.size() << "\n";
604 for (size_t i = 0; i < layers_.size(); i++) {
605 const DrmHwcLayer &layer = layers_[i];
606 *out << " [" << i << "] ";
607
608 DumpBuffer(layer.buffer, out);
609
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700610 if (layer.protected_usage())
611 *out << " protected";
612
Sean Paul04b47ea2015-11-19 21:46:11 -0500613 *out << " transform=";
614 DumpTransform(layer.transform, out);
615 *out << " blending[a=" << (int)layer.alpha
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700616 << "]=" << BlendingToString(layer.blending) << " source_crop";
617 layer.source_crop.Dump(out);
618 *out << " display_frame";
619 layer.display_frame.Dump(out);
620
621 *out << "\n";
622 }
623
624 *out << " Planes: count=" << composition_planes_.size() << "\n";
625 for (size_t i = 0; i < composition_planes_.size(); i++) {
626 const DrmCompositionPlane &comp_plane = composition_planes_[i];
627 *out << " [" << i << "]"
628 << " plane=" << (comp_plane.plane ? comp_plane.plane->id() : -1)
629 << " source_layer=";
630 if (comp_plane.source_layer <= DrmCompositionPlane::kSourceLayerMax) {
631 *out << comp_plane.source_layer;
632 } else {
633 switch (comp_plane.source_layer) {
634 case DrmCompositionPlane::kSourceNone:
635 *out << "NONE";
636 break;
637 case DrmCompositionPlane::kSourcePreComp:
638 *out << "PRECOMP";
639 break;
640 case DrmCompositionPlane::kSourceSquash:
641 *out << "SQUASH";
642 break;
643 default:
644 *out << "<invalid>";
645 break;
646 }
647 }
648
649 *out << "\n";
650 }
651
652 *out << " Squash Regions: count=" << squash_regions_.size() << "\n";
653 for (size_t i = 0; i < squash_regions_.size(); i++) {
654 *out << " [" << i << "] ";
655 DumpRegion(squash_regions_[i], out);
656 *out << "\n";
657 }
658
659 *out << " Pre-Comp Regions: count=" << pre_comp_regions_.size() << "\n";
660 for (size_t i = 0; i < pre_comp_regions_.size(); i++) {
661 *out << " [" << i << "] ";
662 DumpRegion(pre_comp_regions_[i], out);
663 *out << "\n";
664 }
665}
Sean Paul98e73c82015-06-24 14:38:49 -0700666}