summaryrefslogtreecommitdiff
path: root/graphics/composer/2.2/utils/resources/ComposerResources.cpp
blob: a0610a3fda0f52cad23de3329c5d45b9b1d03ea9 (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
/*
 * Copyright 2019 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.
 */

#define LOG_TAG "ComposerResources 2.2"

#include "composer-resources/2.2/ComposerResources.h"

namespace android {
namespace hardware {
namespace graphics {
namespace composer {
namespace V2_2 {
namespace hal {

using V2_1::Display;
using V2_1::Error;
using V2_1::Layer;
using V2_1::hal::ComposerHandleCache;
using V2_1::hal::ComposerHandleImporter;

Error ComposerDisplayResource::getReadbackBuffer(const native_handle_t* inHandle,
                                                 const native_handle_t** outHandle,
                                                 const native_handle** outReplacedHandle) {
    const uint32_t slot = 0;
    const bool fromCache = false;
    return mReadbackBufferCache.getHandle(slot, fromCache, inHandle, outHandle, outReplacedHandle);
}

std::unique_ptr<ComposerResources> ComposerResources::create() {
    auto resources = std::make_unique<ComposerResources>();
    return resources->init() ? std::move(resources) : nullptr;
}

Error ComposerResources::getDisplayReadbackBuffer(Display display, const native_handle_t* rawHandle,
                                                  const native_handle_t** outHandle,
                                                  ReplacedHandle* outReplacedHandle) {
    // import buffer
    const native_handle_t* importedHandle;
    Error error = mImporter.importBuffer(rawHandle, &importedHandle);
    if (error != Error::NONE) {
        return error;
    }

    std::lock_guard<std::mutex> lock(mDisplayResourcesMutex);

    auto iter = mDisplayResources.find(display);
    if (iter == mDisplayResources.end()) {
        mImporter.freeBuffer(importedHandle);
        return Error::BAD_DISPLAY;
    }
    ComposerDisplayResource& displayResource =
            *static_cast<ComposerDisplayResource*>(iter->second.get());

    // update cache
    const native_handle_t* replacedHandle;
    error = displayResource.getReadbackBuffer(importedHandle, outHandle, &replacedHandle);
    if (error != Error::NONE) {
        mImporter.freeBuffer(importedHandle);
        return error;
    }

    outReplacedHandle->reset(&mImporter, replacedHandle);
    return Error::NONE;
}

}  // namespace hal
}  // namespace V2_2
}  // namespace composer
}  // namespace graphics
}  // namespace hardware
}  // namespace android