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" |
Sean Paul | aa18d91 | 2016-05-12 14:28:05 -0400 | [diff] [blame] | 22 | #include "platform.h" |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 23 | |
Sean Paul | c8dcfe0 | 2015-06-10 17:29:05 -0400 | [diff] [blame] | 24 | #include <sstream> |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 25 | #include <stdlib.h> |
| 26 | |
| 27 | #include <cutils/log.h> |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame] | 31 | DrmCompositor::DrmCompositor(DrmResources *drm) : drm_(drm), frame_no_(0) { |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | DrmCompositor::~DrmCompositor() { |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | int DrmCompositor::Init() { |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 38 | for (auto &conn : drm_->connectors()) { |
| 39 | int display = conn->display(); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 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 | } |
Sean Paul | aa18d91 | 2016-05-12 14:28:05 -0400 | [diff] [blame] | 46 | planner_ = Planner::CreateInstance(drm_); |
| 47 | if (!planner_) { |
| 48 | ALOGE("Failed to create planner instance for composition"); |
| 49 | return -ENOMEM; |
| 50 | } |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 51 | |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 52 | return 0; |
| 53 | } |
| 54 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 55 | std::unique_ptr<DrmComposition> DrmCompositor::CreateComposition( |
| 56 | Importer *importer) { |
| 57 | std::unique_ptr<DrmComposition> composition( |
Sean Paul | aa18d91 | 2016-05-12 14:28:05 -0400 | [diff] [blame] | 58 | new DrmComposition(drm_, importer, planner_.get())); |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame] | 59 | int ret = composition->Init(++frame_no_); |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 60 | if (ret) { |
| 61 | ALOGE("Failed to initialize drm composition %d", ret); |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 62 | return nullptr; |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 63 | } |
| 64 | return composition; |
| 65 | } |
| 66 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 67 | int DrmCompositor::QueueComposition( |
| 68 | std::unique_ptr<DrmComposition> composition) { |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 69 | int ret; |
| 70 | |
| 71 | ret = composition->Plan(compositor_map_); |
| 72 | if (ret) |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 73 | return ret; |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 74 | |
| 75 | ret = composition->DisableUnusedPlanes(); |
| 76 | if (ret) |
| 77 | return ret; |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 78 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 79 | for (auto &conn : drm_->connectors()) { |
| 80 | int display = conn->display(); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 81 | int ret = compositor_map_[display].QueueComposition( |
Zach Reizner | 459a5a9 | 2015-07-31 15:12:49 -0700 | [diff] [blame] | 82 | composition->TakeDisplayComposition(display)); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 83 | if (ret) { |
Zach Reizner | 7e88be9 | 2015-10-12 15:20:33 -0700 | [diff] [blame] | 84 | ALOGE("Failed to queue composition for display %d (%d)", display, ret); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 85 | return ret; |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 89 | return 0; |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 92 | int 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 Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 99 | } |
Sean Paul | c8dcfe0 | 2015-06-10 17:29:05 -0400 | [diff] [blame] | 100 | |
| 101 | void DrmCompositor::Dump(std::ostringstream *out) const { |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 102 | *out << "DrmCompositor stats:\n"; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 103 | for (auto &conn : drm_->connectors()) |
| 104 | compositor_map_[conn->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 | } |