1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 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 express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef GLES_GPU_BUFFER_GLES_H 17 #define GLES_GPU_BUFFER_GLES_H 18 19 #include <cstdint> 20 21 #include <render/device/gpu_resource_desc.h> 22 #include <render/gles/intf_device_gles.h> 23 #include <render/namespace.h> 24 25 #include "device/gpu_buffer.h" 26 27 RENDER_BEGIN_NAMESPACE() 28 class Device; 29 class DeviceGLES; 30 struct GpuBufferPlatformDataGL final : public GpuBufferPlatformData { 31 uint32_t buffer { 0 }; 32 uint32_t alignedBindByteSize { 0 }; 33 uint32_t alignedByteSize { 0 }; 34 // map changes offset if buffered 35 uint32_t currentByteOffset { 0 }; 36 // alignedByteSize / mapBufferingCount (if no buffering alignedByteSize == bindMemoryByteSize) 37 uint32_t bindMemoryByteSize { 0 }; 38 // For creating image from EGLClientBuffer 39 uintptr_t eglClientBuffer { 0 }; 40 }; 41 42 class GpuBufferGLES final : public GpuBuffer { 43 public: 44 GpuBufferGLES(Device& device, const GpuBufferDesc& desc); 45 GpuBufferGLES(Device& device, const GpuBufferDesc& desc, const GpuBufferPlatformData& plat); 46 ~GpuBufferGLES() override; 47 48 const GpuBufferDesc& GetDesc() const override; 49 const GpuBufferPlatformDataGL& GetPlatformData() const; 50 51 void* Map() override; 52 void* MapMemory() override; 53 void Unmap() const override; 54 55 private: 56 DeviceGLES& device_; 57 58 GpuBufferPlatformDataGL plat_; 59 GpuBufferDesc desc_; 60 61 // debug assert usage only 62 mutable bool isMapped_ { false }; 63 64 bool isPersistantlyMapped_ { false }; 65 bool isMappable_ { false }; 66 bool isRingBuffer_ { false }; 67 68 uint8_t* data_ { nullptr }; 69 }; 70 RENDER_END_NAMESPACE() 71 72 #endif // GLES_GPU_BUFFER_GLES_H 73