17460160b801b4230f20722efbafcac347312e702Mathias Agopian/* 27460160b801b4230f20722efbafcac347312e702Mathias Agopian** 37460160b801b4230f20722efbafcac347312e702Mathias Agopian** Copyright 2009, The Android Open Source Project 47460160b801b4230f20722efbafcac347312e702Mathias Agopian** 57460160b801b4230f20722efbafcac347312e702Mathias Agopian** Licensed under the Apache License, Version 2.0 (the "License"); 67460160b801b4230f20722efbafcac347312e702Mathias Agopian** you may not use this file except in compliance with the License. 77460160b801b4230f20722efbafcac347312e702Mathias Agopian** You may obtain a copy of the License at 87460160b801b4230f20722efbafcac347312e702Mathias Agopian** 97460160b801b4230f20722efbafcac347312e702Mathias Agopian** http://www.apache.org/licenses/LICENSE-2.0 107460160b801b4230f20722efbafcac347312e702Mathias Agopian** 117460160b801b4230f20722efbafcac347312e702Mathias Agopian** Unless required by applicable law or agreed to in writing, software 127460160b801b4230f20722efbafcac347312e702Mathias Agopian** distributed under the License is distributed on an "AS IS" BASIS, 137460160b801b4230f20722efbafcac347312e702Mathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 147460160b801b4230f20722efbafcac347312e702Mathias Agopian** 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, 487460160b801b4230f20722efbafcac347312e702Mathias Agopian 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, 537460160b801b4230f20722efbafcac347312e702Mathias Agopian 547460160b801b4230f20722efbafcac347312e702Mathias Agopian USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK, 557460160b801b4230f20722efbafcac347312e702Mathias Agopian 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 647460160b801b4230f20722efbafcac347312e702Mathias Agopian 657460160b801b4230f20722efbafcac347312e702Mathias Agopian status_t alloc(uint32_t w, uint32_t h, PixelFormat format, int usage, 667460160b801b4230f20722efbafcac347312e702Mathias Agopian buffer_handle_t* handle, int32_t* stride); 677460160b801b4230f20722efbafcac347312e702Mathias Agopian 687460160b801b4230f20722efbafcac347312e702Mathias Agopian status_t free(buffer_handle_t handle); 697460160b801b4230f20722efbafcac347312e702Mathias Agopian 707460160b801b4230f20722efbafcac347312e702Mathias Agopian void dump(String8& res) const; 71678bdd6349344df254cc0c3377a40fd99e216635Mathias Agopian static void dumpToSystemLog(); 727460160b801b4230f20722efbafcac347312e702Mathias Agopian 737460160b801b4230f20722efbafcac347312e702Mathias Agopianprivate: 747460160b801b4230f20722efbafcac347312e702Mathias Agopian struct alloc_rec_t { 757460160b801b4230f20722efbafcac347312e702Mathias Agopian uint32_t w; 767460160b801b4230f20722efbafcac347312e702Mathias Agopian uint32_t h; 775629eb167638a9ebfa5059177d227c7ac67db46fMathias Agopian uint32_t s; 787460160b801b4230f20722efbafcac347312e702Mathias Agopian PixelFormat format; 797460160b801b4230f20722efbafcac347312e702Mathias Agopian uint32_t usage; 807460160b801b4230f20722efbafcac347312e702Mathias Agopian size_t size; 817460160b801b4230f20722efbafcac347312e702Mathias Agopian }; 827460160b801b4230f20722efbafcac347312e702Mathias Agopian 837460160b801b4230f20722efbafcac347312e702Mathias Agopian static Mutex sLock; 847460160b801b4230f20722efbafcac347312e702Mathias Agopian static KeyedVector<buffer_handle_t, alloc_rec_t> sAllocList; 857460160b801b4230f20722efbafcac347312e702Mathias Agopian 863330b203039dea366d4981db1408a460134b2d2cMathias Agopian friend class Singleton<GraphicBufferAllocator>; 873330b203039dea366d4981db1408a460134b2d2cMathias Agopian GraphicBufferAllocator(); 883330b203039dea366d4981db1408a460134b2d2cMathias Agopian ~GraphicBufferAllocator(); 897460160b801b4230f20722efbafcac347312e702Mathias Agopian 907460160b801b4230f20722efbafcac347312e702Mathias Agopian alloc_device_t *mAllocDev; 917460160b801b4230f20722efbafcac347312e702Mathias Agopian}; 927460160b801b4230f20722efbafcac347312e702Mathias Agopian 937460160b801b4230f20722efbafcac347312e702Mathias Agopian// --------------------------------------------------------------------------- 947460160b801b4230f20722efbafcac347312e702Mathias Agopian}; // namespace android 957460160b801b4230f20722efbafcac347312e702Mathias Agopian 967460160b801b4230f20722efbafcac347312e702Mathias Agopian#endif // ANDROID_BUFFER_ALLOCATOR_H 97