Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 1 | /* |
| 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 Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 20 | #include "drmdisplaycompositor.h" |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 21 | #include "drmresources.h" |
| 22 | |
Sean Paul | c8dcfe0 | 2015-06-10 17:29:05 -0400 | [diff] [blame] | 23 | #include <sstream> |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 24 | #include <stdlib.h> |
| 25 | |
| 26 | #include <cutils/log.h> |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame] | 30 | DrmCompositor::DrmCompositor(DrmResources *drm) : drm_(drm), frame_no_(0) { |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | DrmCompositor::~DrmCompositor() { |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | int DrmCompositor::Init() { |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 37 | 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 Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 47 | return 0; |
| 48 | } |
| 49 | |
Zach Reizner | 459a5a9 | 2015-07-31 15:12:49 -0700 | [diff] [blame] | 50 | DrmComposition *DrmCompositor::CreateComposition(Importer *importer) { |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 51 | DrmComposition *composition = new DrmComposition(drm_, importer); |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 52 | if (!composition) { |
| 53 | ALOGE("Failed to allocate drm composition"); |
| 54 | return NULL; |
| 55 | } |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame] | 56 | int ret = composition->Init(++frame_no_); |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 57 | if (ret) { |
| 58 | ALOGE("Failed to initialize drm composition %d", ret); |
| 59 | delete composition; |
| 60 | return NULL; |
| 61 | } |
| 62 | return composition; |
| 63 | } |
| 64 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 65 | int DrmCompositor::QueueComposition( |
| 66 | std::unique_ptr<DrmComposition> composition) { |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 67 | int ret; |
| 68 | |
| 69 | ret = composition->Plan(compositor_map_); |
| 70 | if (ret) |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 71 | return ret; |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 72 | |
| 73 | ret = composition->DisableUnusedPlanes(); |
| 74 | if (ret) |
| 75 | return ret; |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 76 | |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 77 | for (DrmResources::ConnectorIter iter = drm_->begin_connectors(); |
| 78 | iter != drm_->end_connectors(); ++iter) { |
| 79 | int display = (*iter)->display(); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 80 | int ret = compositor_map_[display].QueueComposition( |
Zach Reizner | 459a5a9 | 2015-07-31 15:12:49 -0700 | [diff] [blame] | 81 | composition->TakeDisplayComposition(display)); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 82 | if (ret) { |
Zach Reizner | 7e88be9 | 2015-10-12 15:20:33 -0700 | [diff] [blame] | 83 | ALOGE("Failed to queue composition for display %d (%d)", display, ret); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 84 | return ret; |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 88 | return 0; |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 91 | int DrmCompositor::Composite() { |
| 92 | /* |
| 93 | * This shouldn't be called, we should be calling Composite() on the display |
| 94 | * compositors directly. |
| 95 | */ |
| 96 | ALOGE("Calling base drm compositor Composite() function"); |
| 97 | return -EINVAL; |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 98 | } |
Sean Paul | c8dcfe0 | 2015-06-10 17:29:05 -0400 | [diff] [blame] | 99 | |
| 100 | void DrmCompositor::Dump(std::ostringstream *out) const { |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 101 | *out << "DrmCompositor stats:\n"; |
| 102 | for (DrmResources::ConnectorIter iter = drm_->begin_connectors(); |
| 103 | iter != drm_->end_connectors(); ++iter) |
| 104 | compositor_map_[(*iter)->display()].Dump(out); |
Sean Paul | c8dcfe0 | 2015-06-10 17:29:05 -0400 | [diff] [blame] | 105 | } |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 106 | } |