blob: d51d514d625dcefced152ab61b88ed8e72329497 [file] [log] [blame]
Mathias Agopian3330b202009-10-05 17:07:12 -07001/*
2 * Copyright (C) 2007 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
Mathias Agopian98e71dd2010-02-11 17:30:52 -080017#define LOG_TAG "GraphicBuffer"
18
Mathias Agopian3330b202009-10-05 17:07:12 -070019#include <stdlib.h>
20#include <stdint.h>
21#include <sys/types.h>
22
Mathias Agopian3330b202009-10-05 17:07:12 -070023#include <utils/Errors.h>
24#include <utils/Log.h>
25
26#include <ui/GraphicBuffer.h>
27#include <ui/GraphicBufferAllocator.h>
28#include <ui/GraphicBufferMapper.h>
29#include <ui/PixelFormat.h>
30
Mathias Agopian3330b202009-10-05 17:07:12 -070031namespace android {
32
33// ===========================================================================
Iliyan Malchev697526b2011-05-01 11:33:26 -070034// Buffer and implementation of ANativeWindowBuffer
Mathias Agopian3330b202009-10-05 17:07:12 -070035// ===========================================================================
36
Dan Stozab1363d32014-03-28 15:10:52 -070037static uint64_t getUniqueId() {
38 static volatile int32_t nextId = 0;
39 uint64_t id = static_cast<uint64_t>(getpid()) << 32;
40 id |= static_cast<uint32_t>(android_atomic_inc(&nextId));
41 return id;
42}
43
Mathias Agopian3330b202009-10-05 17:07:12 -070044GraphicBuffer::GraphicBuffer()
Mathias Agopian54ba51d2009-10-26 20:12:37 -070045 : BASE(), mOwner(ownData), mBufferMapper(GraphicBufferMapper::get()),
Dan Stozab1363d32014-03-28 15:10:52 -070046 mInitCheck(NO_ERROR), mId(getUniqueId())
47{
Dan Stoza01049c82014-11-11 10:32:31 -080048 width =
49 height =
50 stride =
51 format =
Mathias Agopian3330b202009-10-05 17:07:12 -070052 usage = 0;
53 handle = NULL;
54}
55
Dan Stozad3182402014-11-17 12:03:59 -080056GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight,
57 PixelFormat inFormat, uint32_t inUsage)
Mathias Agopian54ba51d2009-10-26 20:12:37 -070058 : BASE(), mOwner(ownData), mBufferMapper(GraphicBufferMapper::get()),
Dan Stozab1363d32014-03-28 15:10:52 -070059 mInitCheck(NO_ERROR), mId(getUniqueId())
Mathias Agopian3330b202009-10-05 17:07:12 -070060{
Dan Stoza01049c82014-11-11 10:32:31 -080061 width =
62 height =
63 stride =
64 format =
Mathias Agopian3330b202009-10-05 17:07:12 -070065 usage = 0;
66 handle = NULL;
Dan Stozad3182402014-11-17 12:03:59 -080067 mInitCheck = initSize(inWidth, inHeight, inFormat, inUsage);
Mathias Agopian3330b202009-10-05 17:07:12 -070068}
69
Dan Stozad3182402014-11-17 12:03:59 -080070GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight,
71 PixelFormat inFormat, uint32_t inUsage, uint32_t inStride,
72 native_handle_t* inHandle, bool keepOwnership)
Mathias Agopian54ba51d2009-10-26 20:12:37 -070073 : BASE(), mOwner(keepOwnership ? ownHandle : ownNone),
74 mBufferMapper(GraphicBufferMapper::get()),
Dan Stozab1363d32014-03-28 15:10:52 -070075 mInitCheck(NO_ERROR), mId(getUniqueId())
Mathias Agopian54ba51d2009-10-26 20:12:37 -070076{
Dan Stozad3182402014-11-17 12:03:59 -080077 width = static_cast<int>(inWidth);
78 height = static_cast<int>(inHeight);
79 stride = static_cast<int>(inStride);
Mathias Agopian54ba51d2009-10-26 20:12:37 -070080 format = inFormat;
Dan Stozad3182402014-11-17 12:03:59 -080081 usage = static_cast<int>(inUsage);
Mathias Agopian54ba51d2009-10-26 20:12:37 -070082 handle = inHandle;
83}
84
Iliyan Malchev697526b2011-05-01 11:33:26 -070085GraphicBuffer::GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership)
Jamie Gennis309d3bb2010-10-07 13:46:55 -070086 : BASE(), mOwner(keepOwnership ? ownHandle : ownNone),
87 mBufferMapper(GraphicBufferMapper::get()),
Dan Stozab1363d32014-03-28 15:10:52 -070088 mInitCheck(NO_ERROR), mWrappedBuffer(buffer), mId(getUniqueId())
Jamie Gennis309d3bb2010-10-07 13:46:55 -070089{
90 width = buffer->width;
91 height = buffer->height;
92 stride = buffer->stride;
93 format = buffer->format;
94 usage = buffer->usage;
95 handle = buffer->handle;
96}
97
Mathias Agopian3330b202009-10-05 17:07:12 -070098GraphicBuffer::~GraphicBuffer()
99{
100 if (handle) {
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800101 free_handle();
102 }
103}
104
105void GraphicBuffer::free_handle()
106{
107 if (mOwner == ownHandle) {
Jamie Gennis309d3bb2010-10-07 13:46:55 -0700108 mBufferMapper.unregisterBuffer(handle);
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800109 native_handle_close(handle);
110 native_handle_delete(const_cast<native_handle*>(handle));
111 } else if (mOwner == ownData) {
112 GraphicBufferAllocator& allocator(GraphicBufferAllocator::get());
113 allocator.free(handle);
Mathias Agopian3330b202009-10-05 17:07:12 -0700114 }
Jamie Gennis309d3bb2010-10-07 13:46:55 -0700115 mWrappedBuffer = 0;
Mathias Agopian3330b202009-10-05 17:07:12 -0700116}
117
118status_t GraphicBuffer::initCheck() const {
Dan Stoza133caac2014-12-01 15:15:31 -0800119 return static_cast<status_t>(mInitCheck);
Mathias Agopian3330b202009-10-05 17:07:12 -0700120}
121
Mathias Agopian678bdd62010-12-03 17:33:09 -0800122void GraphicBuffer::dumpAllocationsToSystemLog()
123{
124 GraphicBufferAllocator::dumpToSystemLog();
125}
126
Iliyan Malchev697526b2011-05-01 11:33:26 -0700127ANativeWindowBuffer* GraphicBuffer::getNativeBuffer() const
Mathias Agopian3330b202009-10-05 17:07:12 -0700128{
Colin Cross18fae752014-07-22 15:55:08 -0700129 LOG_ALWAYS_FATAL_IF(this == NULL, "getNativeBuffer() called on NULL GraphicBuffer");
Iliyan Malchev697526b2011-05-01 11:33:26 -0700130 return static_cast<ANativeWindowBuffer*>(
Mathias Agopian3330b202009-10-05 17:07:12 -0700131 const_cast<GraphicBuffer*>(this));
132}
133
Dan Stozad3182402014-11-17 12:03:59 -0800134status_t GraphicBuffer::reallocate(uint32_t inWidth, uint32_t inHeight,
135 PixelFormat inFormat, uint32_t inUsage)
Mathias Agopian3330b202009-10-05 17:07:12 -0700136{
Mathias Agopian54ba51d2009-10-26 20:12:37 -0700137 if (mOwner != ownData)
138 return INVALID_OPERATION;
139
Dan Stozad3182402014-11-17 12:03:59 -0800140 if (handle &&
141 static_cast<int>(inWidth) == width &&
142 static_cast<int>(inHeight) == height &&
143 inFormat == format &&
144 static_cast<int>(inUsage) == usage)
Mathias Agopian579b3f82010-06-08 19:54:15 -0700145 return NO_ERROR;
146
Mathias Agopian3330b202009-10-05 17:07:12 -0700147 if (handle) {
148 GraphicBufferAllocator& allocator(GraphicBufferAllocator::get());
149 allocator.free(handle);
150 handle = 0;
151 }
Dan Stozad3182402014-11-17 12:03:59 -0800152 return initSize(inWidth, inHeight, inFormat, inUsage);
Mathias Agopian3330b202009-10-05 17:07:12 -0700153}
154
Dan Stoza9de72932015-04-16 17:28:43 -0700155bool GraphicBuffer::needsReallocation(uint32_t inWidth, uint32_t inHeight,
156 PixelFormat inFormat, uint32_t inUsage)
157{
158 if (static_cast<int>(inWidth) != width) return true;
159 if (static_cast<int>(inHeight) != height) return true;
160 if (inFormat != format) return true;
161 if ((static_cast<uint32_t>(usage) & inUsage) != inUsage) return true;
162 return false;
163}
164
Dan Stozad3182402014-11-17 12:03:59 -0800165status_t GraphicBuffer::initSize(uint32_t inWidth, uint32_t inHeight,
166 PixelFormat inFormat, uint32_t inUsage)
Mathias Agopian3330b202009-10-05 17:07:12 -0700167{
Mathias Agopian3330b202009-10-05 17:07:12 -0700168 GraphicBufferAllocator& allocator = GraphicBufferAllocator::get();
Dan Stozad3182402014-11-17 12:03:59 -0800169 uint32_t outStride = 0;
170 status_t err = allocator.alloc(inWidth, inHeight, inFormat, inUsage,
171 &handle, &outStride);
Mathias Agopian3330b202009-10-05 17:07:12 -0700172 if (err == NO_ERROR) {
Dan Stozad3182402014-11-17 12:03:59 -0800173 width = static_cast<int>(inWidth);
174 height = static_cast<int>(inHeight);
175 format = inFormat;
176 usage = static_cast<int>(inUsage);
177 stride = static_cast<int>(outStride);
Mathias Agopian3330b202009-10-05 17:07:12 -0700178 }
179 return err;
180}
181
Dan Stozad3182402014-11-17 12:03:59 -0800182status_t GraphicBuffer::lock(uint32_t inUsage, void** vaddr)
Mathias Agopian3330b202009-10-05 17:07:12 -0700183{
184 const Rect lockBounds(width, height);
Dan Stozad3182402014-11-17 12:03:59 -0800185 status_t res = lock(inUsage, lockBounds, vaddr);
Mathias Agopian3330b202009-10-05 17:07:12 -0700186 return res;
187}
188
Dan Stozad3182402014-11-17 12:03:59 -0800189status_t GraphicBuffer::lock(uint32_t inUsage, const Rect& rect, void** vaddr)
Mathias Agopian3330b202009-10-05 17:07:12 -0700190{
Dan Stozad3182402014-11-17 12:03:59 -0800191 if (rect.left < 0 || rect.right > width ||
192 rect.top < 0 || rect.bottom > height) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000193 ALOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)",
Dan Stoza01049c82014-11-11 10:32:31 -0800194 rect.left, rect.top, rect.right, rect.bottom,
Dan Stozad3182402014-11-17 12:03:59 -0800195 width, height);
Mathias Agopian3330b202009-10-05 17:07:12 -0700196 return BAD_VALUE;
197 }
Dan Stozad3182402014-11-17 12:03:59 -0800198 status_t res = getBufferMapper().lock(handle, inUsage, rect, vaddr);
Mathias Agopian3330b202009-10-05 17:07:12 -0700199 return res;
200}
201
Dan Stozad3182402014-11-17 12:03:59 -0800202status_t GraphicBuffer::lockYCbCr(uint32_t inUsage, android_ycbcr* ycbcr)
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -0700203{
204 const Rect lockBounds(width, height);
Dan Stozad3182402014-11-17 12:03:59 -0800205 status_t res = lockYCbCr(inUsage, lockBounds, ycbcr);
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -0700206 return res;
207}
208
Dan Stozad3182402014-11-17 12:03:59 -0800209status_t GraphicBuffer::lockYCbCr(uint32_t inUsage, const Rect& rect,
210 android_ycbcr* ycbcr)
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -0700211{
Dan Stozad3182402014-11-17 12:03:59 -0800212 if (rect.left < 0 || rect.right > width ||
213 rect.top < 0 || rect.bottom > height) {
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -0700214 ALOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)",
215 rect.left, rect.top, rect.right, rect.bottom,
Dan Stozad3182402014-11-17 12:03:59 -0800216 width, height);
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -0700217 return BAD_VALUE;
218 }
Dan Stozad3182402014-11-17 12:03:59 -0800219 status_t res = getBufferMapper().lockYCbCr(handle, inUsage, rect, ycbcr);
Eino-Ville Talvalac43946b2013-05-04 18:07:43 -0700220 return res;
221}
222
Mathias Agopian3330b202009-10-05 17:07:12 -0700223status_t GraphicBuffer::unlock()
224{
225 status_t res = getBufferMapper().unlock(handle);
226 return res;
227}
228
Dan Stozad3182402014-11-17 12:03:59 -0800229status_t GraphicBuffer::lockAsync(uint32_t inUsage, void** vaddr, int fenceFd)
Francis Hart8f396012014-04-01 15:30:53 +0300230{
231 const Rect lockBounds(width, height);
Dan Stozad3182402014-11-17 12:03:59 -0800232 status_t res = lockAsync(inUsage, lockBounds, vaddr, fenceFd);
Francis Hart8f396012014-04-01 15:30:53 +0300233 return res;
234}
235
Dan Stozad3182402014-11-17 12:03:59 -0800236status_t GraphicBuffer::lockAsync(uint32_t inUsage, const Rect& rect,
237 void** vaddr, int fenceFd)
Francis Hart8f396012014-04-01 15:30:53 +0300238{
Dan Stozad3182402014-11-17 12:03:59 -0800239 if (rect.left < 0 || rect.right > width ||
240 rect.top < 0 || rect.bottom > height) {
Francis Hart8f396012014-04-01 15:30:53 +0300241 ALOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)",
242 rect.left, rect.top, rect.right, rect.bottom,
Dan Stozad3182402014-11-17 12:03:59 -0800243 width, height);
Francis Hart8f396012014-04-01 15:30:53 +0300244 return BAD_VALUE;
245 }
Dan Stozad3182402014-11-17 12:03:59 -0800246 status_t res = getBufferMapper().lockAsync(handle, inUsage, rect, vaddr,
247 fenceFd);
Francis Hart8f396012014-04-01 15:30:53 +0300248 return res;
249}
250
Dan Stozad3182402014-11-17 12:03:59 -0800251status_t GraphicBuffer::lockAsyncYCbCr(uint32_t inUsage, android_ycbcr* ycbcr,
252 int fenceFd)
Francis Hart8f396012014-04-01 15:30:53 +0300253{
254 const Rect lockBounds(width, height);
Dan Stozad3182402014-11-17 12:03:59 -0800255 status_t res = lockAsyncYCbCr(inUsage, lockBounds, ycbcr, fenceFd);
Francis Hart8f396012014-04-01 15:30:53 +0300256 return res;
257}
258
Dan Stozad3182402014-11-17 12:03:59 -0800259status_t GraphicBuffer::lockAsyncYCbCr(uint32_t inUsage, const Rect& rect,
260 android_ycbcr* ycbcr, int fenceFd)
Francis Hart8f396012014-04-01 15:30:53 +0300261{
Dan Stozad3182402014-11-17 12:03:59 -0800262 if (rect.left < 0 || rect.right > width ||
263 rect.top < 0 || rect.bottom > height) {
Francis Hart8f396012014-04-01 15:30:53 +0300264 ALOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)",
265 rect.left, rect.top, rect.right, rect.bottom,
Dan Stozad3182402014-11-17 12:03:59 -0800266 width, height);
Francis Hart8f396012014-04-01 15:30:53 +0300267 return BAD_VALUE;
268 }
Dan Stozad3182402014-11-17 12:03:59 -0800269 status_t res = getBufferMapper().lockAsyncYCbCr(handle, inUsage, rect,
270 ycbcr, fenceFd);
Francis Hart8f396012014-04-01 15:30:53 +0300271 return res;
272}
273
274status_t GraphicBuffer::unlockAsync(int *fenceFd)
275{
276 status_t res = getBufferMapper().unlockAsync(handle, fenceFd);
277 return res;
278}
279
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800280size_t GraphicBuffer::getFlattenedSize() const {
Dan Stozad3182402014-11-17 12:03:59 -0800281 return static_cast<size_t>(10 + (handle ? handle->numInts : 0)) * sizeof(int);
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800282}
Mathias Agopian3330b202009-10-05 17:07:12 -0700283
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800284size_t GraphicBuffer::getFdCount() const {
Dan Stozad3182402014-11-17 12:03:59 -0800285 return static_cast<size_t>(handle ? handle->numFds : 0);
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800286}
287
Mathias Agopiane1424282013-07-29 21:24:40 -0700288status_t GraphicBuffer::flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const {
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800289 size_t sizeNeeded = GraphicBuffer::getFlattenedSize();
290 if (size < sizeNeeded) return NO_MEMORY;
Mathias Agopian3330b202009-10-05 17:07:12 -0700291
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800292 size_t fdCountNeeded = GraphicBuffer::getFdCount();
293 if (count < fdCountNeeded) return NO_MEMORY;
Mathias Agopian3330b202009-10-05 17:07:12 -0700294
Dan Stozab1363d32014-03-28 15:10:52 -0700295 int32_t* buf = static_cast<int32_t*>(buffer);
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800296 buf[0] = 'GBFR';
297 buf[1] = width;
298 buf[2] = height;
299 buf[3] = stride;
300 buf[4] = format;
301 buf[5] = usage;
Dan Stozab1363d32014-03-28 15:10:52 -0700302 buf[6] = static_cast<int32_t>(mId >> 32);
303 buf[7] = static_cast<int32_t>(mId & 0xFFFFFFFFull);
304 buf[8] = 0;
305 buf[9] = 0;
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800306
307 if (handle) {
Dan Stozab1363d32014-03-28 15:10:52 -0700308 buf[8] = handle->numFds;
309 buf[9] = handle->numInts;
Dan Stozad3182402014-11-17 12:03:59 -0800310 memcpy(fds, handle->data,
311 static_cast<size_t>(handle->numFds) * sizeof(int));
312 memcpy(&buf[10], handle->data + handle->numFds,
313 static_cast<size_t>(handle->numInts) * sizeof(int));
Mathias Agopian3330b202009-10-05 17:07:12 -0700314 }
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800315
Mathias Agopiane1424282013-07-29 21:24:40 -0700316 buffer = reinterpret_cast<void*>(static_cast<int*>(buffer) + sizeNeeded);
317 size -= sizeNeeded;
Andy McFaddenbc96e472014-03-17 16:48:23 -0700318 if (handle) {
319 fds += handle->numFds;
Dan Stozad3182402014-11-17 12:03:59 -0800320 count -= static_cast<size_t>(handle->numFds);
Andy McFaddenbc96e472014-03-17 16:48:23 -0700321 }
Mathias Agopiane1424282013-07-29 21:24:40 -0700322
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800323 return NO_ERROR;
324}
325
Mathias Agopiane1424282013-07-29 21:24:40 -0700326status_t GraphicBuffer::unflatten(
327 void const*& buffer, size_t& size, int const*& fds, size_t& count) {
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800328 if (size < 8*sizeof(int)) return NO_MEMORY;
329
330 int const* buf = static_cast<int const*>(buffer);
331 if (buf[0] != 'GBFR') return BAD_TYPE;
332
Dan Stozad3182402014-11-17 12:03:59 -0800333 const size_t numFds = static_cast<size_t>(buf[8]);
334 const size_t numInts = static_cast<size_t>(buf[9]);
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800335
Michael Lentinec168b8a2015-02-18 10:14:18 -0800336 // Limit the maxNumber to be relatively small. The number of fds or ints
337 // should not come close to this number, and the number itself was simply
338 // chosen to be high enough to not cause issues and low enough to prevent
339 // overflow problems.
340 const size_t maxNumber = 4096;
Michael Lentine38803262014-10-31 15:25:03 -0700341 if (numFds >= maxNumber || numInts >= (maxNumber - 10)) {
342 width = height = stride = format = usage = 0;
343 handle = NULL;
Dan Stoza01049c82014-11-11 10:32:31 -0800344 ALOGE("unflatten: numFds or numInts is too large: %zd, %zd",
Michael Lentine38803262014-10-31 15:25:03 -0700345 numFds, numInts);
346 return BAD_VALUE;
347 }
348
Dan Stozab1363d32014-03-28 15:10:52 -0700349 const size_t sizeNeeded = (10 + numInts) * sizeof(int);
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800350 if (size < sizeNeeded) return NO_MEMORY;
351
Michael Lentine38803262014-10-31 15:25:03 -0700352 size_t fdCountNeeded = numFds;
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800353 if (count < fdCountNeeded) return NO_MEMORY;
354
355 if (handle) {
356 // free previous handle if any
357 free_handle();
358 }
359
360 if (numFds || numInts) {
361 width = buf[1];
362 height = buf[2];
363 stride = buf[3];
364 format = buf[4];
365 usage = buf[5];
Dan Stozad3182402014-11-17 12:03:59 -0800366 native_handle* h = native_handle_create(
367 static_cast<int>(numFds), static_cast<int>(numInts));
Michael Lentine38803262014-10-31 15:25:03 -0700368 if (!h) {
369 width = height = stride = format = usage = 0;
370 handle = NULL;
371 ALOGE("unflatten: native_handle_create failed");
372 return NO_MEMORY;
373 }
Dan Stozad3182402014-11-17 12:03:59 -0800374 memcpy(h->data, fds, numFds * sizeof(int));
375 memcpy(h->data + numFds, &buf[10], numInts * sizeof(int));
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800376 handle = h;
377 } else {
378 width = height = stride = format = usage = 0;
379 handle = NULL;
380 }
381
Dan Stozab1363d32014-03-28 15:10:52 -0700382 mId = static_cast<uint64_t>(buf[6]) << 32;
383 mId |= static_cast<uint32_t>(buf[7]);
384
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800385 mOwner = ownHandle;
Jamie Gennis309d3bb2010-10-07 13:46:55 -0700386
387 if (handle != 0) {
Jamie Gennisd69097f2012-08-30 13:28:23 -0700388 status_t err = mBufferMapper.registerBuffer(handle);
389 if (err != NO_ERROR) {
Lingyun Zhu2aff7022012-11-20 19:24:35 +0800390 width = height = stride = format = usage = 0;
391 handle = NULL;
Jamie Gennisd69097f2012-08-30 13:28:23 -0700392 ALOGE("unflatten: registerBuffer failed: %s (%d)",
393 strerror(-err), err);
394 return err;
395 }
Jamie Gennis309d3bb2010-10-07 13:46:55 -0700396 }
397
Mathias Agopiane1424282013-07-29 21:24:40 -0700398 buffer = reinterpret_cast<void const*>(static_cast<int const*>(buffer) + sizeNeeded);
399 size -= sizeNeeded;
400 fds += numFds;
401 count -= numFds;
402
Mathias Agopian98e71dd2010-02-11 17:30:52 -0800403 return NO_ERROR;
Mathias Agopian3330b202009-10-05 17:07:12 -0700404}
405
Mathias Agopian3330b202009-10-05 17:07:12 -0700406// ---------------------------------------------------------------------------
407
408}; // namespace android