diff options
Diffstat (limited to 'libs/ui/GraphicBufferAllocator.cpp')
-rw-r--r-- | libs/ui/GraphicBufferAllocator.cpp | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp index ff550d9..85e9675 100644 --- a/libs/ui/GraphicBufferAllocator.cpp +++ b/libs/ui/GraphicBufferAllocator.cpp @@ -1,17 +1,17 @@ -/* +/* ** ** Copyright 2009, 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 +** 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 +** 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 +** 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. */ @@ -66,11 +66,11 @@ void GraphicBufferAllocator::dump(String8& result) const if (rec.size) { snprintf(buffer, SIZE, "%10p: %7.2f KiB | %4u (%4u) x %4u | %8X | 0x%08x\n", list.keyAt(i), rec.size/1024.0f, - rec.w, rec.s, rec.h, rec.format, rec.usage); + rec.width, rec.stride, rec.height, rec.format, rec.usage); } else { snprintf(buffer, SIZE, "%10p: unknown | %4u (%4u) x %4u | %8X | 0x%08x\n", list.keyAt(i), - rec.w, rec.s, rec.h, rec.format, rec.usage); + rec.width, rec.stride, rec.height, rec.format, rec.usage); } result.append(buffer); total += rec.size; @@ -90,39 +90,40 @@ void GraphicBufferAllocator::dumpToSystemLog() ALOGD("%s", s.string()); } -status_t GraphicBufferAllocator::alloc(uint32_t w, uint32_t h, PixelFormat format, - int usage, buffer_handle_t* handle, int32_t* stride) +status_t GraphicBufferAllocator::alloc(uint32_t width, uint32_t height, + PixelFormat format, uint32_t usage, buffer_handle_t* handle, + uint32_t* stride) { ATRACE_CALL(); + // make sure to not allocate a N x 0 or 0 x N buffer, since this is // allowed from an API stand-point allocate a 1x1 buffer instead. - if (!w || !h) - w = h = 1; + if (!width || !height) + width = height = 1; // we have a h/w allocator and h/w buffer is requested - status_t err; - - err = mAllocDev->alloc(mAllocDev, w, h, format, usage, handle, stride); + status_t err; + + int outStride = 0; + err = mAllocDev->alloc(mAllocDev, static_cast<int>(width), + static_cast<int>(height), format, static_cast<int>(usage), handle, + &outStride); + *stride = static_cast<uint32_t>(outStride); ALOGW_IF(err, "alloc(%u, %u, %d, %08x, ...) failed %d (%s)", - w, h, format, usage, err, strerror(-err)); - + width, height, format, usage, err, strerror(-err)); + if (err == NO_ERROR) { Mutex::Autolock _l(sLock); KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList); - int bpp = bytesPerPixel(format); - if (bpp < 0) { - // probably a HAL custom format. in any case, we don't know - // what its pixel size is. - bpp = 0; - } + uint32_t bpp = bytesPerPixel(format); alloc_rec_t rec; - rec.w = w; - rec.h = h; - rec.s = *stride; + rec.width = width; + rec.height = height; + rec.stride = *stride; rec.format = format; rec.usage = usage; - rec.size = h * stride[0] * bpp; + rec.size = static_cast<size_t>(height * (*stride) * bpp); list.add(*handle, rec); } |