blob: 09da6bffc403ea8733902b9c9e02e54d1791b7f0 [file] [log] [blame]
Sean Paulb386f1b2015-05-13 06:33:23 -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-compositor"
18
19#include "drmcompositor.h"
Sean Paul98e73c82015-06-24 14:38:49 -070020#include "drmdisplaycompositor.h"
Sean Paulb386f1b2015-05-13 06:33:23 -070021#include "drmresources.h"
22
Sean Paulc8dcfe02015-06-10 17:29:05 -040023#include <sstream>
Sean Paulb386f1b2015-05-13 06:33:23 -070024#include <stdlib.h>
25
26#include <cutils/log.h>
Sean Paulb386f1b2015-05-13 06:33:23 -070027
28namespace android {
29
Sean Paulbdc67bf2015-09-21 10:04:02 -040030DrmCompositor::DrmCompositor(DrmResources *drm) : drm_(drm), frame_no_(0) {
Sean Paulb386f1b2015-05-13 06:33:23 -070031}
32
33DrmCompositor::~DrmCompositor() {
Sean Paulb386f1b2015-05-13 06:33:23 -070034}
35
36int DrmCompositor::Init() {
Zach Reiznerff30b522015-10-28 19:08:45 -070037 for (auto &conn : drm_->connectors()) {
38 int display = conn->display();
Sean Paul98e73c82015-06-24 14:38:49 -070039 int ret = compositor_map_[display].Init(drm_, display);
40 if (ret) {
41 ALOGE("Failed to initialize display compositor for %d", display);
42 return ret;
43 }
Sean Paulb386f1b2015-05-13 06:33:23 -070044 }
45
Sean Paulb386f1b2015-05-13 06:33:23 -070046 return 0;
47}
48
Zach Reiznerff30b522015-10-28 19:08:45 -070049std::unique_ptr<DrmComposition> DrmCompositor::CreateComposition(
50 Importer *importer) {
51 std::unique_ptr<DrmComposition> composition(
52 new DrmComposition(drm_, importer));
Sean Paulbdc67bf2015-09-21 10:04:02 -040053 int ret = composition->Init(++frame_no_);
Sean Paulb386f1b2015-05-13 06:33:23 -070054 if (ret) {
55 ALOGE("Failed to initialize drm composition %d", ret);
Zach Reiznerff30b522015-10-28 19:08:45 -070056 return nullptr;
Sean Paulb386f1b2015-05-13 06:33:23 -070057 }
58 return composition;
59}
60
Zach Reizner09807052015-08-13 14:53:41 -070061int DrmCompositor::QueueComposition(
62 std::unique_ptr<DrmComposition> composition) {
Zach Reizner92f8e632015-10-12 17:47:13 -070063 int ret;
64
65 ret = composition->Plan(compositor_map_);
66 if (ret)
Sean Paul2e46fbd2015-07-09 17:22:22 -040067 return ret;
Zach Reizner92f8e632015-10-12 17:47:13 -070068
69 ret = composition->DisableUnusedPlanes();
70 if (ret)
71 return ret;
Sean Paul2e46fbd2015-07-09 17:22:22 -040072
Zach Reiznerff30b522015-10-28 19:08:45 -070073 for (auto &conn : drm_->connectors()) {
74 int display = conn->display();
Sean Paul98e73c82015-06-24 14:38:49 -070075 int ret = compositor_map_[display].QueueComposition(
Zach Reizner459a5a92015-07-31 15:12:49 -070076 composition->TakeDisplayComposition(display));
Sean Paul98e73c82015-06-24 14:38:49 -070077 if (ret) {
Zach Reizner7e88be92015-10-12 15:20:33 -070078 ALOGE("Failed to queue composition for display %d (%d)", display, ret);
Sean Paul98e73c82015-06-24 14:38:49 -070079 return ret;
Sean Paulb386f1b2015-05-13 06:33:23 -070080 }
81 }
82
Sean Paul98e73c82015-06-24 14:38:49 -070083 return 0;
Sean Paulb386f1b2015-05-13 06:33:23 -070084}
85
Sean Paul98e73c82015-06-24 14:38:49 -070086int DrmCompositor::Composite() {
87 /*
88 * This shouldn't be called, we should be calling Composite() on the display
89 * compositors directly.
90 */
91 ALOGE("Calling base drm compositor Composite() function");
92 return -EINVAL;
Sean Paulb386f1b2015-05-13 06:33:23 -070093}
Sean Paulc8dcfe02015-06-10 17:29:05 -040094
95void DrmCompositor::Dump(std::ostringstream *out) const {
Sean Paul98e73c82015-06-24 14:38:49 -070096 *out << "DrmCompositor stats:\n";
Zach Reiznerff30b522015-10-28 19:08:45 -070097 for (auto &conn : drm_->connectors())
98 compositor_map_[conn->display()].Dump(out);
Sean Paulc8dcfe02015-06-10 17:29:05 -040099}
Sean Paulb386f1b2015-05-13 06:33:23 -0700100}