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
23fe2f54fc8a9810708fe05d719721af19aea10a4aMathias Agopian#include <memory>
24fe2f54fc8a9810708fe05d719721af19aea10a4aMathias Agopian#include <string>
25fe2f54fc8a9810708fe05d719721af19aea10a4aMathias Agopian
267460160b801b4230f20722efbafcac347312e702Mathias Agopian#include <cutils/native_handle.h>
277460160b801b4230f20722efbafcac347312e702Mathias Agopian
28cb8405e7e74398aeafc9ef6ddb59af2d7cc6d2a6Chia-I Wu#include <system/window.h>
29cb8405e7e74398aeafc9ef6ddb59af2d7cc6d2a6Chia-I Wu
30cb8405e7e74398aeafc9ef6ddb59af2d7cc6d2a6Chia-I Wu#include <ui/PixelFormat.h>
31cb8405e7e74398aeafc9ef6ddb59af2d7cc6d2a6Chia-I Wu
327460160b801b4230f20722efbafcac347312e702Mathias Agopian#include <utils/Errors.h>
337460160b801b4230f20722efbafcac347312e702Mathias Agopian#include <utils/KeyedVector.h>
34fe2f54fc8a9810708fe05d719721af19aea10a4aMathias Agopian#include <utils/Mutex.h>
357460160b801b4230f20722efbafcac347312e702Mathias Agopian#include <utils/Singleton.h>
367460160b801b4230f20722efbafcac347312e702Mathias Agopian
377460160b801b4230f20722efbafcac347312e702Mathias Agopiannamespace android {
387460160b801b4230f20722efbafcac347312e702Mathias Agopian
399ba189dc5c03040d45dad2080a81115f48f099c3Chia-I Wunamespace Gralloc2 {
409ba189dc5c03040d45dad2080a81115f48f099c3Chia-I Wuclass Allocator;
419ba189dc5c03040d45dad2080a81115f48f099c3Chia-I Wu}
429ba189dc5c03040d45dad2080a81115f48f099c3Chia-I Wu
439ba189dc5c03040d45dad2080a81115f48f099c3Chia-I Wuclass GraphicBufferMapper;
447460160b801b4230f20722efbafcac347312e702Mathias Agopianclass String8;
457460160b801b4230f20722efbafcac347312e702Mathias Agopian
463330b203039dea366d4981db1408a460134b2d2cMathias Agopianclass GraphicBufferAllocator : public Singleton<GraphicBufferAllocator>
477460160b801b4230f20722efbafcac347312e702Mathias Agopian{
487460160b801b4230f20722efbafcac347312e702Mathias Agopianpublic:
493330b203039dea366d4981db1408a460134b2d2cMathias Agopian    static inline GraphicBufferAllocator& get() { return getInstance(); }
507460160b801b4230f20722efbafcac347312e702Mathias Agopian
518deb4da6e8fe4687991da32ae68fa0bca4cb8212Dan Stoza    status_t allocate(uint32_t w, uint32_t h, PixelFormat format,
5282c049843870fc72ff36f48b970dfaf413db0687Chris Forbes            uint32_t layerCount, uint64_t usage,
53e96a325aff9da4e02abeb7b9178592583cf3b78cCraig Donner            buffer_handle_t* handle, uint32_t* stride, uint64_t graphicBufferId,
546ebc46a7c01b22bc19d3c00b493f8d930b15b43aCraig Donner            std::string requestorName);
557460160b801b4230f20722efbafcac347312e702Mathias Agopian
567460160b801b4230f20722efbafcac347312e702Mathias Agopian    status_t free(buffer_handle_t handle);
577460160b801b4230f20722efbafcac347312e702Mathias Agopian
587460160b801b4230f20722efbafcac347312e702Mathias Agopian    void dump(String8& res) const;
59678bdd6349344df254cc0c3377a40fd99e216635Mathias Agopian    static void dumpToSystemLog();
607460160b801b4230f20722efbafcac347312e702Mathias Agopian
617460160b801b4230f20722efbafcac347312e702Mathias Agopianprivate:
627460160b801b4230f20722efbafcac347312e702Mathias Agopian    struct alloc_rec_t {
63303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza        uint32_t width;
64303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza        uint32_t height;
65303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza        uint32_t stride;
667460160b801b4230f20722efbafcac347312e702Mathias Agopian        PixelFormat format;
676ebc46a7c01b22bc19d3c00b493f8d930b15b43aCraig Donner        uint32_t layerCount;
6882c049843870fc72ff36f48b970dfaf413db0687Chris Forbes        uint64_t usage;
697460160b801b4230f20722efbafcac347312e702Mathias Agopian        size_t size;
70024e9313ce69ced1f853d737de680ef9f50ed26dDan Stoza        std::string requestorName;
717460160b801b4230f20722efbafcac347312e702Mathias Agopian    };
72303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza
737460160b801b4230f20722efbafcac347312e702Mathias Agopian    static Mutex sLock;
747460160b801b4230f20722efbafcac347312e702Mathias Agopian    static KeyedVector<buffer_handle_t, alloc_rec_t> sAllocList;
75303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza
763330b203039dea366d4981db1408a460134b2d2cMathias Agopian    friend class Singleton<GraphicBufferAllocator>;
773330b203039dea366d4981db1408a460134b2d2cMathias Agopian    GraphicBufferAllocator();
783330b203039dea366d4981db1408a460134b2d2cMathias Agopian    ~GraphicBufferAllocator();
79303b9a51239d36d237a7d40c67b5085cdb3c1059Dan Stoza
809ba189dc5c03040d45dad2080a81115f48f099c3Chia-I Wu    GraphicBufferMapper& mMapper;
815bac7f36ee9d5ed0c2e8a0141909ca94351965a8Chia-I Wu    const std::unique_ptr<const Gralloc2::Allocator> mAllocator;
827460160b801b4230f20722efbafcac347312e702Mathias Agopian};
837460160b801b4230f20722efbafcac347312e702Mathias Agopian
847460160b801b4230f20722efbafcac347312e702Mathias Agopian// ---------------------------------------------------------------------------
857460160b801b4230f20722efbafcac347312e702Mathias Agopian}; // namespace android
867460160b801b4230f20722efbafcac347312e702Mathias Agopian
877460160b801b4230f20722efbafcac347312e702Mathias Agopian#endif // ANDROID_BUFFER_ALLOCATOR_H
88