summaryrefslogtreecommitdiffstats
path: root/opengl/tests/gralloc
diff options
context:
space:
mode:
Diffstat (limited to 'opengl/tests/gralloc')
-rw-r--r--opengl/tests/gralloc/Android.mk4
-rw-r--r--opengl/tests/gralloc/Buffer.cpp111
-rw-r--r--opengl/tests/gralloc/Buffer.h90
-rw-r--r--opengl/tests/gralloc/BufferAllocator.cpp131
-rw-r--r--opengl/tests/gralloc/BufferAllocator.h96
-rw-r--r--opengl/tests/gralloc/gralloc.cpp8
6 files changed, 5 insertions, 435 deletions
diff --git a/opengl/tests/gralloc/Android.mk b/opengl/tests/gralloc/Android.mk
index a86c8ec..d43c39a 100644
--- a/opengl/tests/gralloc/Android.mk
+++ b/opengl/tests/gralloc/Android.mk
@@ -2,9 +2,7 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
- gralloc.cpp \
- Buffer.cpp \
- BufferAllocator.cpp
+ gralloc.cpp
LOCAL_SHARED_LIBRARIES := \
libcutils \
diff --git a/opengl/tests/gralloc/Buffer.cpp b/opengl/tests/gralloc/Buffer.cpp
deleted file mode 100644
index 3920ff0..0000000
--- a/opengl/tests/gralloc/Buffer.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2007 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 <stdlib.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <utils/Errors.h>
-#include <utils/Log.h>
-
-#include <ui/PixelFormat.h>
-#include <pixelflinger/pixelflinger.h>
-
-#include "Buffer.h"
-#include "BufferAllocator.h"
-
-
-namespace android {
-
-// ===========================================================================
-// Buffer and implementation of android_native_buffer_t
-// ===========================================================================
-
-Buffer::Buffer()
- : SurfaceBuffer(), mInitCheck(NO_ERROR), mVStride(0)
-{
-}
-
-Buffer::Buffer(uint32_t w, uint32_t h, PixelFormat format,
- uint32_t reqUsage, uint32_t flags)
- : SurfaceBuffer(), mInitCheck(NO_INIT), mVStride(0)
-{
- mInitCheck = initSize(w, h, format, reqUsage, flags);
-}
-
-Buffer::~Buffer()
-{
- if (handle) {
- BufferAllocator& allocator(BufferAllocator::get());
- allocator.free(handle);
- }
-}
-
-status_t Buffer::initCheck() const {
- return mInitCheck;
-}
-
-android_native_buffer_t* Buffer::getNativeBuffer() const
-{
- return static_cast<android_native_buffer_t*>(const_cast<Buffer*>(this));
-}
-
-status_t Buffer::reallocate(uint32_t w, uint32_t h, PixelFormat f,
- uint32_t reqUsage, uint32_t flags)
-{
- if (handle) {
- BufferAllocator& allocator(BufferAllocator::get());
- allocator.free(handle);
- handle = 0;
- }
- return initSize(w, h, f, reqUsage, flags);
-}
-
-status_t Buffer::initSize(uint32_t w, uint32_t h, PixelFormat format,
- uint32_t reqUsage, uint32_t flags)
-{
- status_t err = NO_ERROR;
- BufferAllocator& allocator = BufferAllocator::get();
- err = allocator.alloc(w, h, format, reqUsage, &handle, &stride);
- if (err == NO_ERROR) {
- this->width = w;
- this->height = h;
- this->format = format;
- mVStride = 0;
- }
-
- return err;
-}
-
-status_t Buffer::lock(GGLSurface* sur, uint32_t usage)
-{
- void* vaddr;
- status_t res = SurfaceBuffer::lock(usage, &vaddr);
- if (res == NO_ERROR && sur) {
- sur->version = sizeof(GGLSurface);
- sur->width = width;
- sur->height = height;
- sur->stride = stride;
- sur->format = format;
- sur->vstride = mVStride;
- sur->data = static_cast<GGLubyte*>(vaddr);
- }
- return res;
-}
-
-// ---------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/opengl/tests/gralloc/Buffer.h b/opengl/tests/gralloc/Buffer.h
deleted file mode 100644
index 8a32153..0000000
--- a/opengl/tests/gralloc/Buffer.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2007 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.
- */
-
-#ifndef ANDROID_LAYER_BITMAP_H
-#define ANDROID_LAYER_BITMAP_H
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <hardware/gralloc.h>
-
-#include <utils/Atomic.h>
-
-#include <private/ui/SurfaceBuffer.h>
-#include <ui/PixelFormat.h>
-#include <ui/Rect.h>
-
-#include <pixelflinger/pixelflinger.h>
-
-struct android_native_buffer_t;
-
-namespace android {
-
-// ===========================================================================
-// Buffer
-// ===========================================================================
-
-class NativeBuffer;
-
-class Buffer : public SurfaceBuffer
-{
-public:
- enum {
- DONT_CLEAR = 0x00000001,
- SECURE = 0x00000004
- };
-
- Buffer();
-
- // creates w * h buffer
- Buffer(uint32_t w, uint32_t h, PixelFormat format,
- uint32_t reqUsage, uint32_t flags = 0);
-
- // return status
- status_t initCheck() const;
-
- uint32_t getWidth() const { return width; }
- uint32_t getHeight() const { return height; }
- uint32_t getStride() const { return stride; }
- uint32_t getUsage() const { return usage; }
- PixelFormat getPixelFormat() const { return format; }
- Rect getBounds() const { return Rect(width, height); }
-
- status_t lock(GGLSurface* surface, uint32_t usage);
-
- android_native_buffer_t* getNativeBuffer() const;
-
- status_t reallocate(uint32_t w, uint32_t h, PixelFormat f,
- uint32_t reqUsage, uint32_t flags);
-
-private:
- friend class LightRefBase<Buffer>;
- Buffer(const Buffer& rhs);
- virtual ~Buffer();
- Buffer& operator = (const Buffer& rhs);
- const Buffer& operator = (const Buffer& rhs) const;
-
- status_t initSize(uint32_t w, uint32_t h, PixelFormat format,
- uint32_t reqUsage, uint32_t flags);
-
- ssize_t mInitCheck;
- uint32_t mVStride;
-};
-
-}; // namespace android
-
-#endif // ANDROID_LAYER_BITMAP_H
diff --git a/opengl/tests/gralloc/BufferAllocator.cpp b/opengl/tests/gralloc/BufferAllocator.cpp
deleted file mode 100644
index caf9bec..0000000
--- a/opengl/tests/gralloc/BufferAllocator.cpp
+++ /dev/null
@@ -1,131 +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 <sys/mman.h>
-#include <cutils/ashmem.h>
-#include <cutils/log.h>
-
-#include <utils/Singleton.h>
-#include <utils/String8.h>
-
-#include "BufferAllocator.h"
-
-
-namespace android {
-// ---------------------------------------------------------------------------
-
-ANDROID_SINGLETON_STATIC_INSTANCE( BufferAllocator )
-
-Mutex BufferAllocator::sLock;
-KeyedVector<buffer_handle_t, BufferAllocator::alloc_rec_t> 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<buffer_handle_t, alloc_rec_t>& 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 ; i<c ; i++) {
- const alloc_rec_t& rec(list.valueAt(i));
- snprintf(buffer, SIZE, "%10p: %7.2f KiB | %4u x %4u | %2d | 0x%08x\n",
- list.keyAt(i), rec.size/1024.0f,
- rec.w, rec.h, rec.format, rec.usage);
- result.append(buffer);
- total += rec.size;
- }
- snprintf(buffer, SIZE, "Total allocated: %.2f KB\n", total/1024.0f);
- result.append(buffer);
-}
-
-static inline uint32_t clamp(uint32_t c) {
- return c>0 ? 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<buffer_handle_t, alloc_rec_t>& 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<buffer_handle_t, alloc_rec_t>& list(sAllocList);
- list.removeItem(handle);
- }
-
- return err;
-}
-
-// ---------------------------------------------------------------------------
-}; // namespace android
diff --git a/opengl/tests/gralloc/BufferAllocator.h b/opengl/tests/gralloc/BufferAllocator.h
deleted file mode 100644
index a279ded..0000000
--- a/opengl/tests/gralloc/BufferAllocator.h
+++ /dev/null
@@ -1,96 +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.
-*/
-
-#ifndef ANDROID_BUFFER_ALLOCATOR_H
-#define ANDROID_BUFFER_ALLOCATOR_H
-
-#include <stdint.h>
-
-#include <cutils/native_handle.h>
-
-#include <utils/Errors.h>
-#include <utils/KeyedVector.h>
-#include <utils/threads.h>
-#include <utils/Singleton.h>
-
-#include <ui/PixelFormat.h>
-
-#include <hardware/gralloc.h>
-
-
-namespace android {
-// ---------------------------------------------------------------------------
-
-class String8;
-
-class BufferAllocator : public Singleton<BufferAllocator>
-{
-public:
- enum {
- USAGE_SW_READ_NEVER = GRALLOC_USAGE_SW_READ_NEVER,
- USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY,
- USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN,
- USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK,
-
- USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER,
- USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY,
- USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN,
- USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK,
-
- USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK,
-
- USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE,
- USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER,
- USAGE_HW_2D = GRALLOC_USAGE_HW_2D,
- USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK
- };
-
- static inline BufferAllocator& get() { return getInstance(); }
-
-
- status_t alloc(uint32_t w, uint32_t h, PixelFormat format, int usage,
- buffer_handle_t* handle, int32_t* stride);
-
- status_t free(buffer_handle_t handle);
-
- void dump(String8& res) const;
-
-private:
- struct alloc_rec_t {
- uint32_t w;
- uint32_t h;
- PixelFormat format;
- uint32_t usage;
- void* vaddr;
- size_t size;
- };
-
- static Mutex sLock;
- static KeyedVector<buffer_handle_t, alloc_rec_t> sAllocList;
-
- friend class Singleton<BufferAllocator>;
- BufferAllocator();
- ~BufferAllocator();
-
- mutable Mutex mLock;
- alloc_device_t *mAllocDev;
-};
-
-// ---------------------------------------------------------------------------
-}; // namespace android
-
-#endif // ANDROID_BUFFER_ALLOCATOR_H
diff --git a/opengl/tests/gralloc/gralloc.cpp b/opengl/tests/gralloc/gralloc.cpp
index d989bb2..8987040 100644
--- a/opengl/tests/gralloc/gralloc.cpp
+++ b/opengl/tests/gralloc/gralloc.cpp
@@ -22,8 +22,8 @@
#include <utils/StopWatch.h>
#include <utils/Log.h>
-#include "Buffer.h"
-#include <ui/BufferMapper.h>
+#include <ui/GraphicBuffer.h>
+#include <ui/GraphicBufferMapper.h>
using namespace android;
@@ -46,7 +46,7 @@ int main(int argc, char** argv)
memset(temp2, 0, size);
- sp<Buffer> buffer = new Buffer(128, 256, HAL_PIXEL_FORMAT_RGBA_8888,
+ sp<GraphicBuffer> buffer = new GraphicBuffer(128, 256, HAL_PIXEL_FORMAT_RGBA_8888,
GRALLOC_USAGE_SW_READ_OFTEN |
GRALLOC_USAGE_SW_WRITE_OFTEN);
@@ -57,7 +57,7 @@ int main(int argc, char** argv)
}
void* vaddr;
- buffer->SurfaceBuffer::lock(
+ buffer->lock(
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
&vaddr);