1 // Copyright 2022 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expresso or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <EGL/egl.h>
18 #include <EGL/eglext.h>
19 #include <GLES/gl.h>
20 #include <GLES3/gl3.h>
21 
22 #include <memory>
23 
24 #include "ContextHelper.h"
25 #include "Handle.h"
26 #include "aemu/base/files/Stream.h"
27 
28 namespace gfxstream {
29 namespace gl {
30 
31 class BufferGl {
32    public:
33     static std::unique_ptr<BufferGl> create(uint64_t sizeBytes, HandleType hndl,
34                                             ContextHelper* helper);
35 
36     ~BufferGl() = default;
37 
getHndl()38     HandleType getHndl() const { return mHandle; }
getSize()39     uint64_t getSize() const { return mSize; }
40 
41     void read(uint64_t offset, uint64_t size, void* bytes);
42 
43     void subUpdate(uint64_t offset, uint64_t size, const void* bytes);
44 
45     void onSave(android::base::Stream* stream);
46 
47     static std::unique_ptr<BufferGl> onLoad(android::base::Stream* stream, ContextHelper* helper);
48 
49    protected:
50     BufferGl(uint64_t size, HandleType hndl, ContextHelper* helper);
51 
52    private:
53     /*
54     // TODO: GL_EXT_external_buffer
55     GLuint m_buffer = 0;
56     */
57     const uint64_t mSize;
58     const HandleType mHandle;
59     ContextHelper* mContextHelper = nullptr;
60 };
61 
62 }  // namespace gl
63 }  // namespace gfxstream
64