From 6950e428feaccc8164b989ef64e771a99948797a Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 5 Oct 2009 17:07:12 -0700 Subject: fix [2167050] glTexImage2D code path buggy in SurfaceFlinger When EGLImage extension is not available, SurfaceFlinger will fallback to using glTexImage2D and glTexSubImage2D instead, which requires 50% more memory and an extra copy. However this code path has never been exercised and had some bugs which this patch fix. Mainly the scale factor wasn't computed right when falling back on glDrawElements. We also fallback to this mode of operation if a buffer doesn't have the adequate usage bits for EGLImage usage. This changes only code that is currently not executed. Some refactoring was needed to keep the change clean. This doesn't change anything functionaly. --- libs/surfaceflinger/BufferAllocator.cpp | 129 -------------------------------- 1 file changed, 129 deletions(-) delete mode 100644 libs/surfaceflinger/BufferAllocator.cpp (limited to 'libs/surfaceflinger/BufferAllocator.cpp') diff --git a/libs/surfaceflinger/BufferAllocator.cpp b/libs/surfaceflinger/BufferAllocator.cpp deleted file mode 100644 index 3e37bc3..0000000 --- a/libs/surfaceflinger/BufferAllocator.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* -** -** 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 -** -** 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. -*/ - -#include - -#include -#include - -#include "BufferAllocator.h" - - -namespace android { -// --------------------------------------------------------------------------- - -ANDROID_SINGLETON_STATIC_INSTANCE( BufferAllocator ) - -Mutex BufferAllocator::sLock; -KeyedVector BufferAllocator::sAllocList; - -BufferAllocator::BufferAllocator() - : mAllocDev(0) -{ - hw_module_t const* module; - int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); - LOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID); - if (err == 0) { - gralloc_open(module, &mAllocDev); - } -} - -BufferAllocator::~BufferAllocator() -{ - gralloc_close(mAllocDev); -} - -void BufferAllocator::dump(String8& result) const -{ - Mutex::Autolock _l(sLock); - KeyedVector& list(sAllocList); - size_t total = 0; - const size_t SIZE = 512; - char buffer[SIZE]; - snprintf(buffer, SIZE, "Allocated buffers:\n"); - result.append(buffer); - const size_t c = list.size(); - for (size_t i=0 ; i0 ? c : 1; -} - -status_t BufferAllocator::alloc(uint32_t w, uint32_t h, PixelFormat format, - int usage, buffer_handle_t* handle, int32_t* stride) -{ - Mutex::Autolock _l(mLock); - - // make sure to not allocate a 0 x 0 buffer - w = clamp(w); - h = clamp(h); - - // we have a h/w allocator and h/w buffer is requested - status_t err = mAllocDev->alloc(mAllocDev, - w, h, format, usage, handle, stride); - - LOGW_IF(err, "alloc(%u, %u, %d, %08x, ...) failed %d (%s)", - w, h, format, usage, err, strerror(-err)); - - if (err == NO_ERROR) { - Mutex::Autolock _l(sLock); - KeyedVector& list(sAllocList); - alloc_rec_t rec; - rec.w = w; - rec.h = h; - rec.format = format; - rec.usage = usage; - rec.vaddr = 0; - rec.size = h * stride[0] * bytesPerPixel(format); - list.add(*handle, rec); - } else { - String8 s; - dump(s); - LOGD("%s", s.string()); - } - - return err; -} - -status_t BufferAllocator::free(buffer_handle_t handle) -{ - Mutex::Autolock _l(mLock); - - status_t err = mAllocDev->free(mAllocDev, handle); - LOGW_IF(err, "free(...) failed %d (%s)", err, strerror(-err)); - - if (err == NO_ERROR) { - Mutex::Autolock _l(sLock); - KeyedVector& list(sAllocList); - list.removeItem(handle); - } - - return err; -} - -// --------------------------------------------------------------------------- -}; // namespace android -- cgit v1.1