blob: 60aceb1bbd4179aeae463b9b729c5926e2071f45 [file] [log] [blame]
Yin-Chia Yeh64ee5f52020-01-02 17:53:18 +07001/*
2 * Copyright 2021 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 <inttypes.h>
18
19#define LOG_TAG "IGBPBatchOps"
20#define ATRACE_TAG ATRACE_TAG_GRAPHICS
21//#define LOG_NDEBUG 0
22
23#include <gui/IGraphicBufferProducer.h>
24
25namespace android {
26
27/**
28 * Default implementation of batched buffer operations. These default
29 * implementations call into the non-batched version of the same operation.
30 */
31
32status_t IGraphicBufferProducer::requestBuffers(
33 const std::vector<int32_t>& slots,
34 std::vector<RequestBufferOutput>* outputs) {
35 outputs->clear();
36 outputs->reserve(slots.size());
37 for (int32_t slot : slots) {
38 RequestBufferOutput& output = outputs->emplace_back();
39 output.result = requestBuffer(static_cast<int>(slot),
40 &output.buffer);
41 }
42 return NO_ERROR;
43}
44
45status_t IGraphicBufferProducer::dequeueBuffers(
46 const std::vector<DequeueBufferInput>& inputs,
47 std::vector<DequeueBufferOutput>* outputs) {
48 outputs->clear();
49 outputs->reserve(inputs.size());
50 for (const DequeueBufferInput& input : inputs) {
51 DequeueBufferOutput& output = outputs->emplace_back();
52 output.result = dequeueBuffer(
53 &output.slot,
54 &output.fence,
55 input.width,
56 input.height,
57 input.format,
58 input.usage,
59 &output.bufferAge,
60 input.getTimestamps ? &output.timestamps.emplace() : nullptr);
61 }
62 return NO_ERROR;
63}
64
65status_t IGraphicBufferProducer::detachBuffers(
66 const std::vector<int32_t>& slots,
67 std::vector<status_t>* results) {
68 results->clear();
69 results->reserve(slots.size());
70 for (int32_t slot : slots) {
71 results->emplace_back(detachBuffer(slot));
72 }
73 return NO_ERROR;
74}
75
76status_t IGraphicBufferProducer::attachBuffers(
77 const std::vector<sp<GraphicBuffer>>& buffers,
78 std::vector<AttachBufferOutput>* outputs) {
79 outputs->clear();
80 outputs->reserve(buffers.size());
81 for (const sp<GraphicBuffer>& buffer : buffers) {
82 AttachBufferOutput& output = outputs->emplace_back();
83 output.result = attachBuffer(&output.slot, buffer);
84 }
85 return NO_ERROR;
86}
87
88status_t IGraphicBufferProducer::queueBuffers(
89 const std::vector<QueueBufferInput>& inputs,
90 std::vector<QueueBufferOutput>* outputs) {
91 outputs->clear();
92 outputs->reserve(inputs.size());
93 for (const QueueBufferInput& input : inputs) {
94 QueueBufferOutput& output = outputs->emplace_back();
95 output.result = queueBuffer(input.slot, input, &output);
96 }
97 return NO_ERROR;
98}
99
100status_t IGraphicBufferProducer::cancelBuffers(
101 const std::vector<CancelBufferInput>& inputs,
102 std::vector<status_t>* results) {
103 results->clear();
104 results->reserve(inputs.size());
105 for (const CancelBufferInput& input : inputs) {
106 results->emplace_back() = cancelBuffer(input.slot, input.fence);
107 }
108 return NO_ERROR;
109}
110
111status_t IGraphicBufferProducer::query(const std::vector<int32_t> inputs,
112 std::vector<QueryOutput>* outputs) {
113 outputs->clear();
114 outputs->reserve(inputs.size());
115 for (int32_t input : inputs) {
116 QueryOutput& output = outputs->emplace_back();
117 int value{};
118 output.result = static_cast<status_t>(
119 query(static_cast<int>(input), &value));
120 output.value = static_cast<int64_t>(value);
121 }
122 return NO_ERROR;
123}
124
125} // namespace android