• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 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 <memory>
18 
19 #include "Handle.h"
20 #include "aemu/base/files/Stream.h"
21 #include "snapshot/LazySnapshotObj.h"
22 
23 #if GFXSTREAM_ENABLE_HOST_GLES
24 #include "gl/BufferGl.h"
25 #endif
26 
27 namespace gfxstream {
28 namespace gl {
29 class EmulationGl;
30 }  // namespace gl
31 }  // namespace gfxstream
32 
33 namespace gfxstream {
34 namespace vk {
35 class BufferVk;
36 struct VkEmulation;
37 }  // namespace vk
38 }  // namespace gfxstream
39 
40 namespace gfxstream {
41 
42 class Buffer : public android::snapshot::LazySnapshotObj<Buffer> {
43    public:
44     static std::shared_ptr<Buffer> create(gl::EmulationGl* emulationGl,
45                                           vk::VkEmulation* emulationVk, uint64_t size,
46                                           HandleType handle);
47 
48     static std::shared_ptr<Buffer> onLoad(gl::EmulationGl* emulationGl,
49                                           vk::VkEmulation* emulationVk,
50                                           android::base::Stream* stream);
51 
52     void onSave(android::base::Stream* stream);
53     void restore();
54 
getHndl()55     HandleType getHndl() const { return mHandle; }
getSize()56     uint64_t getSize() const { return mSize; }
57 
58     void readToBytes(uint64_t offset, uint64_t size, void* outBytes);
59     bool updateFromBytes(uint64_t offset, uint64_t size, const void* bytes);
60 
61    private:
62     Buffer(HandleType handle, uint64_t size);
63 
64     const uint64_t mSize;
65     const HandleType mHandle;
66 
67 #if GFXSTREAM_ENABLE_HOST_GLES
68     // If GL emulation is enabled.
69     std::unique_ptr<gl::BufferGl> mBufferGl;
70 #endif
71 
72     // If Vk emulation is enabled.
73     std::unique_ptr<vk::BufferVk> mBufferVk;
74 };
75 
76 typedef std::shared_ptr<Buffer> BufferPtr;
77 
78 }  // namespace gfxstream
79