blob: b72b556c6ec06aab5e6895f3e6cfc54c2ec1ed04 [file] [log] [blame]
Jiwen 'Steve' Caid9f2abe2018-10-20 17:03:13 -07001/*
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 Xu93c94902018-11-01 12:22:05 -070017#include <android/hardware_buffer.h>
Jiwen 'Steve' Caid9f2abe2018-10-20 17:03:13 -070018#include <bufferhub/BufferHubService.h>
Fan Xu93c94902018-11-01 12:22:05 -070019#include <log/log.h>
Jiwen 'Steve' Caid9f2abe2018-10-20 17:03:13 -070020
21namespace android {
22namespace frameworks {
23namespace bufferhub {
24namespace V1_0 {
25namespace implementation {
26
Fan Xuca70b7b2018-10-31 13:20:12 -070027using hardware::Void;
Jiwen 'Steve' Caid9f2abe2018-10-20 17:03:13 -070028
Fan Xu93c94902018-11-01 12:22:05 -070029Return<void> BufferHubService::allocateBuffer(const HardwareBufferDescription& description,
30 const uint32_t userMetadataSize,
Fan Xuca70b7b2018-10-31 13:20:12 -070031 allocateBuffer_cb _hidl_cb) {
Fan Xu93c94902018-11-01 12:22:05 -070032 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' Caid9f2abe2018-10-20 17:03:13 -070050 return Void();
51}
52
Fan Xuca70b7b2018-10-31 13:20:12 -070053Return<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' Caid9f2abe2018-10-20 17:03:13 -070058}
59
60} // namespace implementation
61} // namespace V1_0
62} // namespace bufferhub
63} // namespace frameworks
64} // namespace android