1 /*
2  * Copyright (C) 2016 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 ANDROID_C2BUFFER_H_
18 #define ANDROID_C2BUFFER_H_
19 
20 #include <cutils/native_handle.h>
21 #include <hardware/gralloc.h>
22 
23 /* Use android native handle for C2Handle */
24 typedef ::native_handle_t C2Handle;
25 
26 namespace android {
27 
28 /**
29  * Android platform buffer/memory usage bits.
30  */
31 struct C2AndroidMemoryUsage : public C2MemoryUsage {
C2AndroidMemoryUsageC2AndroidMemoryUsage32     inline C2AndroidMemoryUsage(const C2MemoryUsage &usage) : C2MemoryUsage(usage) { }
33 
34 // public:
35     /**
36      * Reuse gralloc flags where possible, as Codec 2.0 API only uses bits 0 and 1.
37      */
38     enum consumer_t : uint64_t {
39         RENDERSCRIPT_READ = GRALLOC_USAGE_RENDERSCRIPT,
40         HW_TEXTURE_READ   = GRALLOC_USAGE_HW_TEXTURE,
41         HW_COMPOSER_READ  = GRALLOC_USAGE_HW_COMPOSER,
42         // gralloc does not define a video decoder read usage flag, so use encoder for
43         // now
44         HW_CODEC_READ     = GRALLOC_USAGE_HW_VIDEO_ENCODER,
45         READ_PROTECTED    = GRALLOC_USAGE_PROTECTED,
46     };
47 
48     enum producer_t : uint64_t {
49         RENDERSCRIPT_WRITE = GRALLOC_USAGE_RENDERSCRIPT,
50         HW_TEXTURE_WRITE   = GRALLOC_USAGE_HW_RENDER,
51         HW_COMPOSER_WRITE  = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER,
52         HW_CODEC_WRITE     = GRALLOC_USAGE_HW_VIDEO_ENCODER,
53         // gralloc does not define a write protected usage flag, so use read protected
54         // now
55         WRITE_PROTECTED    = GRALLOC_USAGE_PROTECTED,
56     };
57 
58     /**
59      * Convert from gralloc usage.
60      */
61     static C2MemoryUsage FromGrallocUsage(uint64_t usage);
62 
63     /**
64      * Convert to gralloc usage.
65      */
66     uint64_t asGrallocUsage() const;
67 };
68 
69 }  // namespace android
70 
71 #endif  // ANDROID_C2BUFFER_H_
72