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 ANDROID_GRAPHIC_BUFFER_H
18 #define ANDROID_GRAPHIC_BUFFER_H
19 
20 #include <stdint.h>
21 #include <sys/types.h>
22 #include <ui/ANativeObjectBase.h>
23 #include <ui/PixelFormat.h>
24 #include <ui/Rect.h>
25 #include <utils/RefBase.h>
26 
27 #include <vector>
28 
29 namespace android {
30 
31 class GraphicBuffer : public ANativeObjectBase<ANativeWindowBuffer, GraphicBuffer, RefBase> {
32 public:
GraphicBuffer(uint32_t w,uint32_t h)33     GraphicBuffer(uint32_t w, uint32_t h) {
34         data.resize(w * h);
35         reserved[0] = data.data();
36         width = w;
37         height = h;
38     }
39 
getWidth()40     uint32_t getWidth() const {
41         return static_cast<uint32_t>(width);
42     }
43 
getHeight()44     uint32_t getHeight() const {
45         return static_cast<uint32_t>(height);
46     }
47 
getStride()48     uint32_t getStride() const {
49         return static_cast<uint32_t>(width);
50     }
51 
getUsage()52     uint64_t getUsage() const {
53         return 0;
54     }
55 
getPixelFormat()56     PixelFormat getPixelFormat() const {
57         return PIXEL_FORMAT_RGBA_8888;
58     }
59 
getBounds()60     Rect getBounds() const {
61         return Rect(width, height);
62     }
63 
lockAsyncYCbCr(uint32_t inUsage,const Rect & rect,android_ycbcr * ycbcr,int fenceFd)64     status_t lockAsyncYCbCr(uint32_t inUsage, const Rect& rect, android_ycbcr* ycbcr, int fenceFd) {
65         return OK;
66     }
67 
68     status_t lockAsync(uint32_t inUsage, const Rect& rect, void** vaddr, int fenceFd,
69                        int32_t* outBytesPerPixel = nullptr, int32_t* outBytesPerStride = nullptr) {
70         *vaddr = data.data();
71         return OK;
72     }
73 
unlockAsync(int * fenceFd)74     status_t unlockAsync(int* fenceFd) {
75         return OK;
76     }
77 
78 private:
79     std::vector<uint32_t> data;
80 };
81 
82 }; // namespace android
83 
84 #endif // ANDROID_GRAPHIC_BUFFER_H
85