OSDN Git Service

drm_hwcomposer: polish for old DRM wrapper code
[android-x86/external-drm_hwcomposer.git] / drmcompositor.cpp
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"
20 #include "drmdisplaycompositor.h"
21 #include "drmresources.h"
22
23 #include <sstream>
24 #include <stdlib.h>
25
26 #include <cutils/log.h>
27
28 namespace android {
29
30 DrmCompositor::DrmCompositor(DrmResources *drm) : drm_(drm), frame_no_(0) {
31 }
32
33 DrmCompositor::~DrmCompositor() {
34 }
35
36 int DrmCompositor::Init() {
37   for (auto &conn : drm_->connectors()) {
38     int display = conn->display();
39     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     }
44   }
45
46   return 0;
47 }
48
49 std::unique_ptr<DrmComposition> DrmCompositor::CreateComposition(
50     Importer *importer) {
51   std::unique_ptr<DrmComposition> composition(
52       new DrmComposition(drm_, importer));
53   int ret = composition->Init(++frame_no_);
54   if (ret) {
55     ALOGE("Failed to initialize drm composition %d", ret);
56     return nullptr;
57   }
58   return composition;
59 }
60
61 int DrmCompositor::QueueComposition(
62     std::unique_ptr<DrmComposition> composition) {
63   int ret;
64
65   ret = composition->Plan(compositor_map_);
66   if (ret)
67     return ret;
68
69   ret = composition->DisableUnusedPlanes();
70   if (ret)
71     return ret;
72
73   for (auto &conn : drm_->connectors()) {
74     int display = conn->display();
75     int ret = compositor_map_[display].QueueComposition(
76         composition->TakeDisplayComposition(display));
77     if (ret) {
78       ALOGE("Failed to queue composition for display %d (%d)", display, ret);
79       return ret;
80     }
81   }
82
83   return 0;
84 }
85
86 int 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;
93 }
94
95 void DrmCompositor::Dump(std::ostringstream *out) const {
96   *out << "DrmCompositor stats:\n";
97   for (auto &conn : drm_->connectors())
98     compositor_map_[conn->display()].Dump(out);
99 }
100 }