blob: c1f3ed8e86b803fe4fd529f381012905dcdfa61c [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"
Sean Paulaa18d912016-05-12 14:28:05 -040022#include "platform.h"
Sean Paulb386f1b2015-05-13 06:33:23 -070023
Sean Paulc8dcfe02015-06-10 17:29:05 -040024#include <sstream>
Sean Paulb386f1b2015-05-13 06:33:23 -070025#include <stdlib.h>
26
27#include <cutils/log.h>
Sean Paulb386f1b2015-05-13 06:33:23 -070028
29namespace android {
30
Sean Paulbdc67bf2015-09-21 10:04:02 -040031DrmCompositor::DrmCompositor(DrmResources *drm) : drm_(drm), frame_no_(0) {
Sean Paulb386f1b2015-05-13 06:33:23 -070032}
33
34DrmCompositor::~DrmCompositor() {
Sean Paulb386f1b2015-05-13 06:33:23 -070035}
36
37int DrmCompositor::Init() {
Zach Reiznerff30b522015-10-28 19:08:45 -070038 for (auto &conn : drm_->connectors()) {
39 int display = conn->display();
Sean Paul98e73c82015-06-24 14:38:49 -070040 int ret = compositor_map_[display].Init(drm_, display);
41 if (ret) {
42 ALOGE("Failed to initialize display compositor for %d", display);
43 return ret;
44 }
Sean Paulb386f1b2015-05-13 06:33:23 -070045 }
Sean Paulaa18d912016-05-12 14:28:05 -040046 planner_ = Planner::CreateInstance(drm_);
47 if (!planner_) {
48 ALOGE("Failed to create planner instance for composition");
49 return -ENOMEM;
50 }
Sean Paulb386f1b2015-05-13 06:33:23 -070051
Sean Paulb386f1b2015-05-13 06:33:23 -070052 return 0;
53}
54
Zach Reiznerff30b522015-10-28 19:08:45 -070055std::unique_ptr<DrmComposition> DrmCompositor::CreateComposition(
56 Importer *importer) {
57 std::unique_ptr<DrmComposition> composition(
Sean Paulaa18d912016-05-12 14:28:05 -040058 new DrmComposition(drm_, importer, planner_.get()));
Sean Paulbdc67bf2015-09-21 10:04:02 -040059 int ret = composition->Init(++frame_no_);
Sean Paulb386f1b2015-05-13 06:33:23 -070060 if (ret) {
61 ALOGE("Failed to initialize drm composition %d", ret);
Zach Reiznerff30b522015-10-28 19:08:45 -070062 return nullptr;
Sean Paulb386f1b2015-05-13 06:33:23 -070063 }
64 return composition;
65}
66
Zach Reizner09807052015-08-13 14:53:41 -070067int DrmCompositor::QueueComposition(
68 std::unique_ptr<DrmComposition> composition) {
Zach Reizner92f8e632015-10-12 17:47:13 -070069 int ret;
70
71 ret = composition->Plan(compositor_map_);
72 if (ret)
Sean Paul2e46fbd2015-07-09 17:22:22 -040073 return ret;
Zach Reizner92f8e632015-10-12 17:47:13 -070074
75 ret = composition->DisableUnusedPlanes();
76 if (ret)
77 return ret;
Sean Paul2e46fbd2015-07-09 17:22:22 -040078
Zach Reiznerff30b522015-10-28 19:08:45 -070079 for (auto &conn : drm_->connectors()) {
80 int display = conn->display();
Sean Paul98e73c82015-06-24 14:38:49 -070081 int ret = compositor_map_[display].QueueComposition(
Zach Reizner459a5a92015-07-31 15:12:49 -070082 composition->TakeDisplayComposition(display));
Sean Paul98e73c82015-06-24 14:38:49 -070083 if (ret) {
Zach Reizner7e88be92015-10-12 15:20:33 -070084 ALOGE("Failed to queue composition for display %d (%d)", display, ret);
Sean Paul98e73c82015-06-24 14:38:49 -070085 return ret;
Sean Paulb386f1b2015-05-13 06:33:23 -070086 }
87 }
88
Sean Paul98e73c82015-06-24 14:38:49 -070089 return 0;
Sean Paulb386f1b2015-05-13 06:33:23 -070090}
91
Sean Paul98e73c82015-06-24 14:38:49 -070092int DrmCompositor::Composite() {
93 /*
94 * This shouldn't be called, we should be calling Composite() on the display
95 * compositors directly.
96 */
97 ALOGE("Calling base drm compositor Composite() function");
98 return -EINVAL;
Sean Paulb386f1b2015-05-13 06:33:23 -070099}
Sean Paulc8dcfe02015-06-10 17:29:05 -0400100
101void DrmCompositor::Dump(std::ostringstream *out) const {
Sean Paul98e73c82015-06-24 14:38:49 -0700102 *out << "DrmCompositor stats:\n";
Zach Reiznerff30b522015-10-28 19:08:45 -0700103 for (auto &conn : drm_->connectors())
104 compositor_map_[conn->display()].Dump(out);
Sean Paulc8dcfe02015-06-10 17:29:05 -0400105}
Sean Paulb386f1b2015-05-13 06:33:23 -0700106}