summaryrefslogtreecommitdiff
path: root/libacryl/acrylic.cpp
blob: 0039560551919717f3ea0e1301837b4c1fc96c8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 * Copyright Samsung Electronics Co.,LTD.
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <algorithm>

#include <log/log.h>

#include <hardware/exynos/acryl.h>

#include "acrylic_internal.h"

Acrylic::Acrylic(const HW2DCapability &capability)
    : mCapability(capability), mHasBackgroundColor(false),
      mMaxTargetLuminance(100), mMinTargetLuminance(0), mTargetDisplayInfo(nullptr),
      mCanvas(this, AcrylicCanvas::CANVAS_TARGET)
{
    ALOGD_TEST("Created a new Acrylic on %p", this);
}

Acrylic::~Acrylic()
{
    mCanvas.disconnectLayer();

    for (auto layer: mLayers) {
        layer->disconnectLayer();
        removeTransitData(layer);
    }

    ALOGD_TEST("Destroyed Acrylic on %p", this);
}

AcrylicLayer *Acrylic::createLayer()
{
    if (mLayers.size() >= getCapabilities().maxLayerCount()) {
        ALOGE("Full of composit layer: current %zu, max %u",
                mLayers.size() , getCapabilities().maxLayerCount());
        return NULL;
    }

    auto *layer = new AcrylicLayer(this);
    if (!layer) {
        ALOGE("Failed to create a new compositing layer");
        return NULL;
    }

    mLayers.push_back(layer);

    ALOGD_TEST("A new Acrylic layer is created. Total %zd layers", mLayers.size());

    return layer;
}

void Acrylic::removeLayer(AcrylicLayer *layer)
{
    auto it = find(std::begin(mLayers), std::end(mLayers), layer);

    if (it == std::end(mLayers)) {
        ALOGE("Deleting an unregistered layer");
    } else {
        removeTransitData(*it);
        mLayers.erase(it);
    }
}

int Acrylic::prioritize(int priority)
{
    if ((priority < -1) || (priority > 15)) {
        ALOGE("Invalid priority %d", priority);
        return -1;
    }

    return 0;
}

bool Acrylic::requestPerformanceQoS(AcrylicPerformanceRequest __unused *request)
{
    return true;
}

bool Acrylic::setHDRToneMapCoefficients(uint32_t __unused *matrix[2], int __unused num_elements)
{
    return true;
}

bool Acrylic::validateAllLayers()
{
    const HW2DCapability &cap = getCapabilities();

    if (!mCanvas.isSettingOkay()) {
        ALOGE("Incomplete settting (flags: %#x) on the target layer",
              mCanvas.getSettingFlags());
        return false;
    }

    if (mCanvas.isCompressed() && !cap.isFeatureSupported(HW2DCapability::FEATURE_AFBC_ENCODE)) {
        ALOGE("AFBC encoding is not supported");
        return false;
    }

    if (mCanvas.isUOrder() && !cap.isFeatureSupported(HW2DCapability::FEATURE_UORDER_WRITE)) {
        ALOGE("Writing in U-Order is not supported");
        return false;
    }

    bool prot = false;
    hw2d_rect_t rect;
    hw2d_coord_t xy = mCanvas.getImageDimension();

    for (auto layer: mLayers) {
        if (!layer->isSettingOkay()) {
            ALOGE("Incomplete settting (flags: %#x) on a layer of %zu layers",
                  layer->getSettingFlags(), mLayers.size());
            return false;
        }

        if (layer->isCompressed() && !cap.isFeatureSupported(HW2DCapability::FEATURE_AFBC_DECODE)) {
            ALOGE("AFBC decoding is not supported");
            return false;
        }

        if (layer->isUOrder() && !cap.isFeatureSupported(HW2DCapability::FEATURE_UORDER_READ)) {
            ALOGE("Reading a texture in U-Order is not supported");
            return false;
        }

        if ((layer->getPlaneAlpha() != 255) && !cap.isFeatureSupported(HW2DCapability::FEATURE_PLANE_ALPHA)) {
            ALOGE("Plane alpha is not supported but given %u for plane alpha", layer->getPlaneAlpha());
            return false;
        }

        rect = layer->getTargetRect();
        if (area_is_zero(rect)) {
            // If no target area is specified to a source layer,
            // the entire region of the target image becomes the target area.
            // Then, check the scaling capability
            hw2d_rect_t ir = layer->getImageRect();
            if (!!(layer->getCompositAttr() & AcrylicLayer::ATTR_NORESAMPLING)) {
                if (!cap.supportedResizing(ir.size, xy, layer->getTransform())) {
                    ALOGE("Unsupported resizing from %dx%d@(%d,%d) --> Target %dx%d with transform %d",
                          ir.size.hori, ir.size.vert, ir.pos.hori, ir.pos.vert,
                          xy.hori, xy.vert, layer->getTransform());
                    return false;
                }
            } else {
                if (!cap.supportedResampling(ir.size, xy, layer->getTransform())) {
                    ALOGE("Unsupported scaling from %dx%d@(%d,%d) --> Target %dx%d with transform %d",
                          ir.size.hori, ir.size.vert, ir.pos.hori, ir.pos.vert,
                          xy.hori, xy.vert, layer->getTransform());
                    return false;
                }
            }
        } else if (rect > xy) {
            ALOGE("Target area %dx%d@(%d,%d) of a layer of %zu layers is out of bound (%dx%d)",
                    rect.size.hori, rect.size.vert, rect.pos.hori, rect.pos.vert,
                    mLayers.size(), xy.hori, xy.vert);
            return false;
        }

        prot = prot || layer->isProtected();
    }

    if (prot && !mCanvas.isProtected()) {
        ALOGE("Target image is not protected while a source layer is protected");
        return false;
    }

    return true;
}

void Acrylic::sortLayers()
{
    std::sort(std::begin(mLayers), std::end(mLayers), [] (auto l1, auto l2) { return l1->getZOrder() < l2->getZOrder(); });
}