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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
/*
* 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_NDEBUG 0
#define LOG_TAG "B2HGraphicBufferProducer@2.0"
#include <android-base/logging.h>
#include <android/hardware/graphics/bufferqueue/2.0/types.h>
#include <android/hardware/graphics/common/1.2/types.h>
#include <gui/bufferqueue/2.0/H2BProducerListener.h>
#include <gui/bufferqueue/2.0/B2HGraphicBufferProducer.h>
#include <gui/bufferqueue/2.0/types.h>
#include <ui/GraphicBuffer.h>
#include <ui/Rect.h>
#include <ui/Region.h>
#include <vndk/hardware_buffer.h>
namespace android {
namespace hardware {
namespace graphics {
namespace bufferqueue {
namespace V2_0 {
namespace utils {
namespace /* unnamed */ {
using BQueueBufferInput = ::android::
IGraphicBufferProducer::QueueBufferInput;
using HQueueBufferInput = ::android::hardware::graphics::bufferqueue::V2_0::
IGraphicBufferProducer::QueueBufferInput;
using BQueueBufferOutput = ::android::
IGraphicBufferProducer::QueueBufferOutput;
using HQueueBufferOutput = ::android::hardware::graphics::bufferqueue::V2_0::
IGraphicBufferProducer::QueueBufferOutput;
using ::android::hardware::graphics::bufferqueue::V2_0::utils::b2h;
using ::android::hardware::graphics::bufferqueue::V2_0::utils::h2b;
bool b2h(BQueueBufferOutput const& from, HQueueBufferOutput* to) {
to->width = from.width;
to->height = from.height;
to->transformHint = static_cast<int32_t>(from.transformHint);
to->numPendingBuffers = from.numPendingBuffers;
to->nextFrameNumber = from.nextFrameNumber;
to->bufferReplaced = from.bufferReplaced;
return true;
}
} // unnamed namespace
// B2HGraphicBufferProducer
// ========================
B2HGraphicBufferProducer::B2HGraphicBufferProducer(
sp<BGraphicBufferProducer> const& base)
: mBase{base} {
}
Return<HStatus> B2HGraphicBufferProducer::setMaxDequeuedBufferCount(
int32_t maxDequeuedBuffers) {
HStatus hStatus{};
bool converted = b2h(
mBase->setMaxDequeuedBufferCount(
static_cast<int>(maxDequeuedBuffers)),
&hStatus);
return {converted ? hStatus : HStatus::UNKNOWN_ERROR};
}
Return<void> B2HGraphicBufferProducer::requestBuffer(
int32_t slot,
requestBuffer_cb _hidl_cb) {
sp<GraphicBuffer> bBuffer;
HStatus hStatus{};
HardwareBuffer hBuffer{};
uint32_t hGenerationNumber{};
bool converted =
b2h(mBase->requestBuffer(
static_cast<int>(slot), &bBuffer),
&hStatus) &&
b2h(bBuffer, &hBuffer, &hGenerationNumber);
_hidl_cb(converted ? hStatus : HStatus::UNKNOWN_ERROR,
hBuffer, hGenerationNumber);
return {};
}
Return<HStatus> B2HGraphicBufferProducer::setAsyncMode(bool async) {
HStatus hStatus{};
bool converted = b2h(mBase->setAsyncMode(async), &hStatus);
return {converted ? hStatus : HStatus::UNKNOWN_ERROR};
}
Return<void> B2HGraphicBufferProducer::dequeueBuffer(
DequeueBufferInput const& input,
dequeueBuffer_cb _hidl_cb) {
int bSlot{};
sp<BFence> bFence;
HStatus hStatus{};
DequeueBufferOutput hOutput{};
HFenceWrapper hFenceWrapper;
bool converted =
b2h(mBase->dequeueBuffer(
&bSlot,
&bFence,
input.width,
input.height,
static_cast<PixelFormat>(input.format),
input.usage,
&hOutput.bufferAge,
nullptr /* outTimestamps */),
&hStatus,
&hOutput.bufferNeedsReallocation,
&hOutput.releaseAllBuffers) &&
b2h(bFence, &hFenceWrapper);
hOutput.fence = hFenceWrapper.getHandle();
_hidl_cb(converted ? hStatus : HStatus::UNKNOWN_ERROR,
static_cast<int32_t>(bSlot),
hOutput);
return {};
}
Return<HStatus> B2HGraphicBufferProducer::detachBuffer(int32_t slot) {
HStatus hStatus{};
bool converted = b2h(
mBase->detachBuffer(static_cast<int>(slot)), &hStatus);
return {converted ? hStatus : HStatus::UNKNOWN_ERROR};
}
Return<void> B2HGraphicBufferProducer::detachNextBuffer(
detachNextBuffer_cb _hidl_cb) {
sp<GraphicBuffer> bBuffer;
sp<BFence> bFence;
HStatus hStatus{};
HardwareBuffer hBuffer{};
HFenceWrapper hFenceWrapper;
bool converted =
b2h(mBase->detachNextBuffer(&bBuffer, &bFence), &hStatus) &&
b2h(bBuffer, &hBuffer) &&
b2h(bFence, &hFenceWrapper);
_hidl_cb(converted ? hStatus : HStatus::UNKNOWN_ERROR,
hBuffer,
hFenceWrapper.getHandle());
return {};
}
Return<void> B2HGraphicBufferProducer::attachBuffer(
HardwareBuffer const& hBuffer,
uint32_t generationNumber,
attachBuffer_cb _hidl_cb) {
sp<GraphicBuffer> bBuffer;
if (!h2b(hBuffer, &bBuffer) || !bBuffer) {
_hidl_cb(HStatus::UNKNOWN_ERROR,
static_cast<int32_t>(SlotIndex::INVALID),
false);
return {};
}
bBuffer->setGenerationNumber(generationNumber);
int bSlot{};
HStatus hStatus{};
bool releaseAllBuffers{};
bool converted = b2h(
mBase->attachBuffer(&bSlot, bBuffer), &hStatus,
nullptr /* bufferNeedsReallocation */,
&releaseAllBuffers);
_hidl_cb(converted ? hStatus : HStatus::UNKNOWN_ERROR,
static_cast<int32_t>(bSlot),
releaseAllBuffers);
return {};
}
Return<void> B2HGraphicBufferProducer::queueBuffer(
int32_t slot,
QueueBufferInput const& hInput,
queueBuffer_cb _hidl_cb) {
BQueueBufferInput bInput{
hInput.timestamp,
hInput.isAutoTimestamp,
static_cast<android_dataspace>(hInput.dataSpace),
{}, /* crop */
0 /* scalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE */,
static_cast<uint32_t>(hInput.transform),
{}, /* fence */
static_cast<uint32_t>(hInput.stickyTransform),
false /* getFrameTimestamps */};
// Convert crop.
if (!h2b(hInput.crop, &bInput.crop)) {
_hidl_cb(HStatus::UNKNOWN_ERROR, QueueBufferOutput{});
return {};
}
// Convert surfaceDamage.
if (!h2b(hInput.surfaceDamage, &bInput.surfaceDamage)) {
_hidl_cb(HStatus::UNKNOWN_ERROR, QueueBufferOutput{});
return {};
}
// Convert fence.
if (!h2b(hInput.fence, &bInput.fence)) {
_hidl_cb(HStatus::UNKNOWN_ERROR, QueueBufferOutput{});
return {};
}
BQueueBufferOutput bOutput{};
HStatus hStatus{};
QueueBufferOutput hOutput{};
bool converted =
b2h(
mBase->queueBuffer(static_cast<int>(slot), bInput, &bOutput),
&hStatus) &&
b2h(bOutput, &hOutput);
_hidl_cb(converted ? hStatus : HStatus::UNKNOWN_ERROR, hOutput);
return {};
}
Return<HStatus> B2HGraphicBufferProducer::cancelBuffer(
int32_t slot,
hidl_handle const& fence) {
sp<BFence> bFence;
if (!h2b(fence.getNativeHandle(), &bFence)) {
return {HStatus::UNKNOWN_ERROR};
}
HStatus hStatus{};
bool converted = b2h(
mBase->cancelBuffer(static_cast<int>(slot), bFence),
&hStatus);
return {converted ? hStatus : HStatus::UNKNOWN_ERROR};
}
Return<void> B2HGraphicBufferProducer::query(int32_t what, query_cb _hidl_cb) {
int value{};
int result = mBase->query(static_cast<int>(what), &value);
_hidl_cb(static_cast<int32_t>(result), static_cast<int32_t>(value));
return {};
}
Return<void> B2HGraphicBufferProducer::connect(
sp<HProducerListener> const& hListener,
HConnectionType hConnectionType,
bool producerControlledByApp,
connect_cb _hidl_cb) {
sp<BProducerListener> bListener = new H2BProducerListener(hListener);
int bConnectionType{};
if (!bListener || !h2b(hConnectionType, &bConnectionType)) {
_hidl_cb(HStatus::UNKNOWN_ERROR, QueueBufferOutput{});
return {};
}
BQueueBufferOutput bOutput{};
HStatus hStatus{};
QueueBufferOutput hOutput{};
bool converted =
b2h(mBase->connect(bListener,
bConnectionType,
producerControlledByApp,
&bOutput),
&hStatus) &&
b2h(bOutput, &hOutput);
_hidl_cb(converted ? hStatus : HStatus::UNKNOWN_ERROR, hOutput);
return {};
}
Return<HStatus> B2HGraphicBufferProducer::disconnect(
HConnectionType hConnectionType) {
int bConnectionType;
if (!h2b(hConnectionType, &bConnectionType)) {
return {HStatus::UNKNOWN_ERROR};
}
HStatus hStatus{};
bool converted = b2h(mBase->disconnect(bConnectionType), &hStatus);
return {converted ? hStatus : HStatus::UNKNOWN_ERROR};
}
Return<HStatus> B2HGraphicBufferProducer::allocateBuffers(
uint32_t width, uint32_t height,
uint32_t format, uint64_t usage) {
mBase->allocateBuffers(
width, height, static_cast<PixelFormat>(format), usage);
return {HStatus::OK};
}
Return<HStatus> B2HGraphicBufferProducer::allowAllocation(bool allow) {
HStatus hStatus{};
bool converted = b2h(mBase->allowAllocation(allow), &hStatus);
return {converted ? hStatus : HStatus::UNKNOWN_ERROR};
}
Return<HStatus> B2HGraphicBufferProducer::setGenerationNumber(
uint32_t generationNumber) {
HStatus hStatus{};
bool converted = b2h(
mBase->setGenerationNumber(generationNumber),
&hStatus);
return {converted ? hStatus : HStatus::UNKNOWN_ERROR};
}
Return<HStatus> B2HGraphicBufferProducer::setDequeueTimeout(
int64_t timeoutNs) {
HStatus hStatus{};
bool converted = b2h(
mBase->setDequeueTimeout(static_cast<nsecs_t>(timeoutNs)),
&hStatus);
return {converted ? hStatus : HStatus::UNKNOWN_ERROR};
}
Return<uint64_t> B2HGraphicBufferProducer::getUniqueId() {
uint64_t outId{};
HStatus hStatus{};
bool converted = b2h(mBase->getUniqueId(&outId), &hStatus);
return {converted ? outId : 0};
}
Return<void> B2HGraphicBufferProducer::getConsumerName(
getConsumerName_cb _hidl_cb) {
_hidl_cb(hidl_string{mBase->getConsumerName().c_str()});
return {};
}
} // namespace utils
} // namespace V2_0
} // namespace bufferqueue
} // namespace graphics
} // namespace hardware
} // namespace android
|