1303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza/* 27460160b801b4230f20722efbafcac347312e702Mathias Agopian** 37460160b801b4230f20722efbafcac347312e702Mathias Agopian** Copyright 2009, The Android Open Source Project 47460160b801b4230f20722efbafcac347312e702Mathias Agopian** 5303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza** Licensed under the Apache License, Version 2.0 (the "License"); 6303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza** you may not use this file except in compliance with the License. 7303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza** You may obtain a copy of the License at 87460160b801b4230f20722efbafcac347312e702Mathias Agopian** 9303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza** http://www.apache.org/licenses/LICENSE-2.0 107460160b801b4230f20722efbafcac347312e702Mathias Agopian** 11303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza** Unless required by applicable law or agreed to in writing, software 12303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza** distributed under the License is distributed on an "AS IS" BASIS, 13303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza** See the License for the specific language governing permissions and 157460160b801b4230f20722efbafcac347312e702Mathias Agopian** limitations under the License. 167460160b801b4230f20722efbafcac347312e702Mathias Agopian*/ 177460160b801b4230f20722efbafcac347312e702Mathias Agopian 187460160b801b4230f20722efbafcac347312e702Mathias Agopian#ifndef ANDROID_BUFFER_ALLOCATOR_H 197460160b801b4230f20722efbafcac347312e702Mathias Agopian#define ANDROID_BUFFER_ALLOCATOR_H 207460160b801b4230f20722efbafcac347312e702Mathias Agopian 217460160b801b4230f20722efbafcac347312e702Mathias Agopian#include <stdint.h> 227460160b801b4230f20722efbafcac347312e702Mathias Agopian 237460160b801b4230f20722efbafcac347312e702Mathias Agopian#include <cutils/native_handle.h> 247460160b801b4230f20722efbafcac347312e702Mathias Agopian 257460160b801b4230f20722efbafcac347312e702Mathias Agopian#include <utils/Errors.h> 267460160b801b4230f20722efbafcac347312e702Mathias Agopian#include <utils/KeyedVector.h> 277460160b801b4230f20722efbafcac347312e702Mathias Agopian#include <utils/threads.h> 287460160b801b4230f20722efbafcac347312e702Mathias Agopian#include <utils/Singleton.h> 297460160b801b4230f20722efbafcac347312e702Mathias Agopian 307460160b801b4230f20722efbafcac347312e702Mathias Agopian#include <ui/PixelFormat.h> 317460160b801b4230f20722efbafcac347312e702Mathias Agopian 327460160b801b4230f20722efbafcac347312e702Mathias Agopian#include <hardware/gralloc.h> 337460160b801b4230f20722efbafcac347312e702Mathias Agopian 347460160b801b4230f20722efbafcac347312e702Mathias Agopian 357460160b801b4230f20722efbafcac347312e702Mathias Agopiannamespace android { 367460160b801b4230f20722efbafcac347312e702Mathias Agopian// --------------------------------------------------------------------------- 377460160b801b4230f20722efbafcac347312e702Mathias Agopian 387460160b801b4230f20722efbafcac347312e702Mathias Agopianclass String8; 397460160b801b4230f20722efbafcac347312e702Mathias Agopian 403330b203039dea366d4981db1408a460134b2d2cMathias Agopianclass GraphicBufferAllocator : public Singleton<GraphicBufferAllocator> 417460160b801b4230f20722efbafcac347312e702Mathias Agopian{ 427460160b801b4230f20722efbafcac347312e702Mathias Agopianpublic: 437460160b801b4230f20722efbafcac347312e702Mathias Agopian enum { 447460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_SW_READ_NEVER = GRALLOC_USAGE_SW_READ_NEVER, 457460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY, 467460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN, 477460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK, 48303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza 497460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER, 507460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY, 517460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN, 527460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK, 53303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza 547460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK, 55303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza 567460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE, 577460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER, 587460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_HW_2D = GRALLOC_USAGE_HW_2D, 597460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK 607460160b801b4230f20722efbafcac347312e702Mathias Agopian }; 617460160b801b4230f20722efbafcac347312e702Mathias Agopian 623330b203039dea366d4981db1408a460134b2d2cMathias Agopian static inline GraphicBufferAllocator& get() { return getInstance(); } 637460160b801b4230f20722efbafcac347312e702Mathias Agopian 64303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza status_t alloc(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage, 65303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza buffer_handle_t* handle, uint32_t* stride); 667460160b801b4230f20722efbafcac347312e702Mathias Agopian 677460160b801b4230f20722efbafcac347312e702Mathias Agopian status_t free(buffer_handle_t handle); 687460160b801b4230f20722efbafcac347312e702Mathias Agopian 697460160b801b4230f20722efbafcac347312e702Mathias Agopian void dump(String8& res) const; 70678bdd6349344df254cc0c3377a40fd99e216635Mathias Agopian static void dumpToSystemLog(); 717460160b801b4230f20722efbafcac347312e702Mathias Agopian 727460160b801b4230f20722efbafcac347312e702Mathias Agopianprivate: 737460160b801b4230f20722efbafcac347312e702Mathias Agopian struct alloc_rec_t { 74303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza uint32_t width; 75303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza uint32_t height; 76303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza uint32_t stride; 777460160b801b4230f20722efbafcac347312e702Mathias Agopian PixelFormat format; 787460160b801b4230f20722efbafcac347312e702Mathias Agopian uint32_t usage; 797460160b801b4230f20722efbafcac347312e702Mathias Agopian size_t size; 807460160b801b4230f20722efbafcac347312e702Mathias Agopian }; 81303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza 827460160b801b4230f20722efbafcac347312e702Mathias Agopian static Mutex sLock; 837460160b801b4230f20722efbafcac347312e702Mathias Agopian static KeyedVector<buffer_handle_t, alloc_rec_t> sAllocList; 84303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza 853330b203039dea366d4981db1408a460134b2d2cMathias Agopian friend class Singleton<GraphicBufferAllocator>; 863330b203039dea366d4981db1408a460134b2d2cMathias Agopian GraphicBufferAllocator(); 873330b203039dea366d4981db1408a460134b2d2cMathias Agopian ~GraphicBufferAllocator(); 88303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza 897460160b801b4230f20722efbafcac347312e702Mathias Agopian alloc_device_t *mAllocDev; 907460160b801b4230f20722efbafcac347312e702Mathias Agopian}; 917460160b801b4230f20722efbafcac347312e702Mathias Agopian 927460160b801b4230f20722efbafcac347312e702Mathias Agopian// --------------------------------------------------------------------------- 937460160b801b4230f20722efbafcac347312e702Mathias Agopian}; // namespace android 947460160b801b4230f20722efbafcac347312e702Mathias Agopian 957460160b801b4230f20722efbafcac347312e702Mathias Agopian#endif // ANDROID_BUFFER_ALLOCATOR_H 96