blob: 3bab93f75ca1fb6f03dcdfaed06a08badcfdb131 [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 Paul98e73c82015-06-24 14:38:49 -070030DrmCompositor::DrmCompositor(DrmResources *drm) : drm_(drm) {
Sean Paulb386f1b2015-05-13 06:33:23 -070031}
32
33DrmCompositor::~DrmCompositor() {
Sean Paulb386f1b2015-05-13 06:33:23 -070034}
35
36int DrmCompositor::Init() {
Sean Paul98e73c82015-06-24 14:38:49 -070037 for (DrmResources::ConnectorIter iter = drm_->begin_connectors();
38 iter != drm_->end_connectors(); ++iter) {
39 int display = (*iter)->display();
40 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 }
46
Sean Paulb386f1b2015-05-13 06:33:23 -070047 return 0;
48}
49
Puneet Kumar1c5e5562015-07-30 03:35:38 +000050Composition *DrmCompositor::CreateComposition(Importer *importer) {
Sean Paul98e73c82015-06-24 14:38:49 -070051 DrmComposition *composition = new DrmComposition(drm_, importer);
Sean Paulb386f1b2015-05-13 06:33:23 -070052 if (!composition) {
53 ALOGE("Failed to allocate drm composition");
54 return NULL;
55 }
56 int ret = composition->Init();
57 if (ret) {
58 ALOGE("Failed to initialize drm composition %d", ret);
59 delete composition;
60 return NULL;
61 }
62 return composition;
63}
64
Puneet Kumar1c5e5562015-07-30 03:35:38 +000065int DrmCompositor::QueueComposition(Composition *composition) {
66 DrmComposition *drm_composition = (DrmComposition *)composition;
67
68 int ret = drm_composition->DisableUnusedPlanes();
Sean Paul2e46fbd2015-07-09 17:22:22 -040069 if (ret) {
70 ALOGE("Failed to disable unused planes %d", ret);
71 return ret;
72 }
73
Sean Paulb386f1b2015-05-13 06:33:23 -070074 for (DrmResources::ConnectorIter iter = drm_->begin_connectors();
75 iter != drm_->end_connectors(); ++iter) {
76 int display = (*iter)->display();
Sean Paul98e73c82015-06-24 14:38:49 -070077 int ret = compositor_map_[display].QueueComposition(
Puneet Kumar1c5e5562015-07-30 03:35:38 +000078 drm_composition->TakeDisplayComposition(display));
Sean Paul98e73c82015-06-24 14:38:49 -070079 if (ret) {
80 ALOGE("Failed to queue composition for display %d", display);
Sean Paulfd138282015-07-10 16:43:06 -040081 delete composition;
Sean Paul98e73c82015-06-24 14:38:49 -070082 return ret;
Sean Paulb386f1b2015-05-13 06:33:23 -070083 }
84 }
85
Sean Paul98e73c82015-06-24 14:38:49 -070086 return 0;
Sean Paulb386f1b2015-05-13 06:33:23 -070087}
88
Sean Paul98e73c82015-06-24 14:38:49 -070089int DrmCompositor::Composite() {
90 /*
91 * This shouldn't be called, we should be calling Composite() on the display
92 * compositors directly.
93 */
94 ALOGE("Calling base drm compositor Composite() function");
95 return -EINVAL;
Sean Paulb386f1b2015-05-13 06:33:23 -070096}
Sean Paulc8dcfe02015-06-10 17:29:05 -040097
98void DrmCompositor::Dump(std::ostringstream *out) const {
Sean Paul98e73c82015-06-24 14:38:49 -070099 *out << "DrmCompositor stats:\n";
100 for (DrmResources::ConnectorIter iter = drm_->begin_connectors();
101 iter != drm_->end_connectors(); ++iter)
102 compositor_map_[(*iter)->display()].Dump(out);
Sean Paulc8dcfe02015-06-10 17:29:05 -0400103}
Sean Paulb386f1b2015-05-13 06:33:23 -0700104}