1/*
2 * Copyright (C) 2016 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#include <sstream>
18
19#include <ui/Rect.h>
20
21#include "Hwc2TestClientTarget.h"
22
23int Hwc2TestClientTarget::getBuffer(const Hwc2TestLayers& testLayers,
24        const std::set<hwc2_layer_t>& clientLayers,
25        const std::set<hwc2_layer_t>& clearLayers, bool flipClientTarget,
26        const Area& displayArea, buffer_handle_t* outHandle,
27        int32_t* outAcquireFence)
28{
29    if (!flipClientTarget) {
30        bool needsClientTarget = false;
31
32        for (auto clientLayer : clientLayers) {
33            if (testLayers.getVisibleRegion(clientLayer).numRects > 0) {
34                needsClientTarget = true;
35                break;
36            }
37        }
38
39        if (!needsClientTarget) {
40           *outHandle = nullptr;
41           *outAcquireFence = -1;
42           return 0;
43        }
44    }
45
46    return mBuffer.get(outHandle, outAcquireFence, displayArea,
47            &testLayers, &clientLayers, &clearLayers);
48}
49
50
51Hwc2TestClientTargetSupport::Hwc2TestClientTargetSupport(
52        Hwc2TestCoverage coverage, const Area& displayArea)
53    : mBufferArea(coverage, displayArea),
54      mDataspace(coverage),
55      mSurfaceDamage(coverage)
56{
57    mBufferArea.setDependent(&mSurfaceDamage);
58}
59
60std::string Hwc2TestClientTargetSupport::dump() const
61{
62    std::stringstream dmp;
63
64    dmp << "client target: \n";
65
66    for (auto property : properties) {
67        dmp << property->dump();
68    }
69
70    return dmp.str();
71}
72
73void Hwc2TestClientTargetSupport::reset()
74{
75    for (auto property : properties) {
76        property->reset();
77    }
78}
79
80bool Hwc2TestClientTargetSupport::advance()
81{
82    for (auto property : properties) {
83        if (property->advance())
84            return true;
85    }
86    return false;
87}
88
89Area Hwc2TestClientTargetSupport::getBufferArea() const
90{
91    return mBufferArea.get();
92}
93
94android_dataspace_t Hwc2TestClientTargetSupport::getDataspace() const
95{
96    return mDataspace.get();
97}
98
99const hwc_region_t Hwc2TestClientTargetSupport::getSurfaceDamage() const
100{
101    return mSurfaceDamage.get();
102}
103