OSDN Git Service

drm_hwcomposer: Split the drm compositor into per-display threads
[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) {
31 }
32
33 DrmCompositor::~DrmCompositor() {
34 }
35
36 int DrmCompositor::Init() {
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     }
45   }
46
47   return 0;
48 }
49
50 Composition *DrmCompositor::CreateComposition(Importer *importer) {
51   DrmComposition *composition = new DrmComposition(drm_, importer);
52   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
65 int DrmCompositor::QueueComposition(Composition *composition) {
66   DrmComposition *drm_composition = (DrmComposition *)composition;
67   for (DrmResources::ConnectorIter iter = drm_->begin_connectors();
68        iter != drm_->end_connectors(); ++iter) {
69     int display = (*iter)->display();
70     int ret = compositor_map_[display].QueueComposition(
71         drm_composition->TakeDisplayComposition(display));
72     if (ret) {
73       ALOGE("Failed to queue composition for display %d", display);
74       return ret;
75     }
76   }
77
78   return 0;
79 }
80
81 int DrmCompositor::Composite() {
82   /*
83    * This shouldn't be called, we should be calling Composite() on the display
84    * compositors directly.
85    */
86   ALOGE("Calling base drm compositor Composite() function");
87   return -EINVAL;
88 }
89
90 void DrmCompositor::Dump(std::ostringstream *out) const {
91   *out << "DrmCompositor stats:\n";
92   for (DrmResources::ConnectorIter iter = drm_->begin_connectors();
93        iter != drm_->end_connectors(); ++iter)
94     compositor_map_[(*iter)->display()].Dump(out);
95 }
96 }