Jiwen 'Steve' Cai | d9f2abe | 2018-10-20 17:03:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Fan Xu | 93c9490 | 2018-11-01 12:22:05 -0700 | [diff] [blame^] | 17 | #include <android/hardware_buffer.h> |
Jiwen 'Steve' Cai | d9f2abe | 2018-10-20 17:03:13 -0700 | [diff] [blame] | 18 | #include <bufferhub/BufferHubService.h> |
Fan Xu | 93c9490 | 2018-11-01 12:22:05 -0700 | [diff] [blame^] | 19 | #include <log/log.h> |
Jiwen 'Steve' Cai | d9f2abe | 2018-10-20 17:03:13 -0700 | [diff] [blame] | 20 | |
| 21 | namespace android { |
| 22 | namespace frameworks { |
| 23 | namespace bufferhub { |
| 24 | namespace V1_0 { |
| 25 | namespace implementation { |
| 26 | |
Fan Xu | ca70b7b | 2018-10-31 13:20:12 -0700 | [diff] [blame] | 27 | using hardware::Void; |
Jiwen 'Steve' Cai | d9f2abe | 2018-10-20 17:03:13 -0700 | [diff] [blame] | 28 | |
Fan Xu | 93c9490 | 2018-11-01 12:22:05 -0700 | [diff] [blame^] | 29 | Return<void> BufferHubService::allocateBuffer(const HardwareBufferDescription& description, |
| 30 | const uint32_t userMetadataSize, |
Fan Xu | ca70b7b | 2018-10-31 13:20:12 -0700 | [diff] [blame] | 31 | allocateBuffer_cb _hidl_cb) { |
Fan Xu | 93c9490 | 2018-11-01 12:22:05 -0700 | [diff] [blame^] | 32 | AHardwareBuffer_Desc desc; |
| 33 | memcpy(&desc, &description, sizeof(AHardwareBuffer_Desc)); |
| 34 | |
| 35 | std::shared_ptr<BufferNode> node = |
| 36 | std::make_shared<BufferNode>(desc.width, desc.height, desc.layers, desc.format, |
| 37 | desc.usage, userMetadataSize); |
| 38 | if (node == nullptr || !node->IsValid()) { |
| 39 | ALOGE("%s: creating BufferNode failed.", __FUNCTION__); |
| 40 | _hidl_cb(/*bufferClient=*/nullptr, /*status=*/BufferHubStatus::ALLOCATION_FAILED); |
| 41 | return Void(); |
| 42 | } |
| 43 | |
| 44 | sp<BufferClient> client = new BufferClient(node); |
| 45 | // Add it to list for bookkeeping and dumpsys. |
| 46 | std::lock_guard<std::mutex> lock(mClientListMutex); |
| 47 | mClientList.push_back(client); |
| 48 | |
| 49 | _hidl_cb(/*bufferClient=*/client, /*status=*/BufferHubStatus::NO_ERROR); |
Jiwen 'Steve' Cai | d9f2abe | 2018-10-20 17:03:13 -0700 | [diff] [blame] | 50 | return Void(); |
| 51 | } |
| 52 | |
Fan Xu | ca70b7b | 2018-10-31 13:20:12 -0700 | [diff] [blame] | 53 | Return<void> BufferHubService::importBuffer(const hidl_handle& /*nativeHandle*/, |
| 54 | importBuffer_cb _hidl_cb) { |
| 55 | // TODO(b/118614157): implement buffer import |
| 56 | _hidl_cb(/*bufferClient=*/nullptr, /*status=*/BufferHubStatus::NO_ERROR); |
| 57 | return Void(); |
Jiwen 'Steve' Cai | d9f2abe | 2018-10-20 17:03:13 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | } // namespace implementation |
| 61 | } // namespace V1_0 |
| 62 | } // namespace bufferhub |
| 63 | } // namespace frameworks |
| 64 | } // namespace android |