1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef STAGEFRIGHT_CODEC2_ALLOCATOR_BLOB_H_
18 #define STAGEFRIGHT_CODEC2_ALLOCATOR_BLOB_H_
19 
20 #include <functional>
21 
22 #include <C2AllocatorGralloc.h>
23 #include <C2Buffer.h>
24 
25 namespace android {
26 
27 class C2AllocatorBlob : public C2Allocator {
28 public:
29     virtual id_t getId() const override;
30 
31     virtual C2String getName() const override;
32 
33     virtual std::shared_ptr<const Traits> getTraits() const override;
34 
35     virtual c2_status_t newLinearAllocation(
36             uint32_t capacity, C2MemoryUsage usage,
37             std::shared_ptr<C2LinearAllocation> *allocation) override;
38 
39     virtual c2_status_t priorLinearAllocation(
40             const C2Handle *handle,
41             std::shared_ptr<C2LinearAllocation> *allocation) override;
42 
43     C2AllocatorBlob(id_t id);
44 
45     virtual ~C2AllocatorBlob() override;
46 
47     static bool isValid(const C2Handle* const o);
48 
49 private:
50     std::shared_ptr<const Traits> mTraits;
51     // Design as C2AllocatorGralloc-backed to unify Gralloc implementations.
52     std::shared_ptr<C2Allocator> mC2AllocatorGralloc;
53 };
54 
55 } // namespace android
56 
57 #endif // STAGEFRIGHT_CODEC2_ALLOCATOR_BLOB_H_
58