• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 "ComposerResources 2.2"
18 
19 #include "composer-resources/2.2/ComposerResources.h"
20 
21 namespace android {
22 namespace hardware {
23 namespace graphics {
24 namespace composer {
25 namespace V2_2 {
26 namespace hal {
27 
28 using V2_1::Display;
29 using V2_1::Error;
30 using V2_1::Layer;
31 using V2_1::hal::ComposerHandleCache;
32 using V2_1::hal::ComposerHandleImporter;
33 
getReadbackBuffer(const native_handle_t * inHandle,const native_handle_t ** outHandle,const native_handle ** outReplacedHandle)34 Error ComposerDisplayResource::getReadbackBuffer(const native_handle_t* inHandle,
35                                                  const native_handle_t** outHandle,
36                                                  const native_handle** outReplacedHandle) {
37     const uint32_t slot = 0;
38     const bool fromCache = false;
39     return mReadbackBufferCache.getHandle(slot, fromCache, inHandle, outHandle, outReplacedHandle);
40 }
41 
create()42 std::unique_ptr<ComposerResources> ComposerResources::create() {
43     auto resources = std::make_unique<ComposerResources>();
44     return resources->init() ? std::move(resources) : nullptr;
45 }
46 
getDisplayReadbackBuffer(Display display,const native_handle_t * rawHandle,const native_handle_t ** outHandle,ReplacedHandle * outReplacedHandle)47 Error ComposerResources::getDisplayReadbackBuffer(Display display, const native_handle_t* rawHandle,
48                                                   const native_handle_t** outHandle,
49                                                   ReplacedHandle* outReplacedHandle) {
50     // import buffer
51     const native_handle_t* importedHandle;
52     Error error = mImporter.importBuffer(rawHandle, &importedHandle);
53     if (error != Error::NONE) {
54         return error;
55     }
56 
57     std::lock_guard<std::mutex> lock(mDisplayResourcesMutex);
58 
59     auto iter = mDisplayResources.find(display);
60     if (iter == mDisplayResources.end()) {
61         mImporter.freeBuffer(importedHandle);
62         return Error::BAD_DISPLAY;
63     }
64     ComposerDisplayResource& displayResource =
65             *static_cast<ComposerDisplayResource*>(iter->second.get());
66 
67     // update cache
68     const native_handle_t* replacedHandle;
69     error = displayResource.getReadbackBuffer(importedHandle, outHandle, &replacedHandle);
70     if (error != Error::NONE) {
71         mImporter.freeBuffer(importedHandle);
72         return error;
73     }
74 
75     outReplacedHandle->reset(&mImporter, replacedHandle);
76     return Error::NONE;
77 }
78 
79 }  // namespace hal
80 }  // namespace V2_2
81 }  // namespace composer
82 }  // namespace graphics
83 }  // namespace hardware
84 }  // namespace android
85