1 /*
2  * Copyright (c) 2024 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_SWAPCHAIN_GLES_H
17 #define GLES_SWAPCHAIN_GLES_H
18 
19 #include <cstdint>
20 
21 #include <base/containers/vector.h>
22 #include <render/device/gpu_resource_desc.h>
23 #include <render/namespace.h>
24 
25 #include "device/swapchain.h"
26 #include "gles/gpu_image_gles.h"
27 
28 RENDER_BEGIN_NAMESPACE()
29 class Device;
30 class DeviceGLES;
31 struct SwapchainCreateInfo;
32 
33 struct SwapchainImagesGLES {
34     BASE_NS::vector<uint32_t> images;
35 
36     uint32_t width { 0 };
37     uint32_t height { 0 };
38 };
39 
40 struct SwapchainPlatformDataGL final {
41     uintptr_t surface; // currently EGLSurface (on GLES) or HDC (on GL/Windows)
42 #if RENDER_GL_FLIP_Y_SWAPCHAIN
43     BASE_NS::vector<uint32_t> fbos; // FBO for the swapchain.
44 #endif
45     uint32_t swapchainImageIndex;
46     SwapchainImagesGLES swapchainImages;
47     bool vsync;
48     GpuImagePlatformDataGL depthPlatformData;
49 };
50 
51 class SwapchainGLES final : public Swapchain {
52 public:
53     SwapchainGLES(Device& device, const SwapchainCreateInfo& swapchainCreateInfo);
54     ~SwapchainGLES() override;
55 
56     const SwapchainPlatformDataGL& GetPlatformData() const;
57     const GpuImageDesc& GetDesc() const override;
58     const GpuImageDesc& GetDescDepthBuffer() const override;
59 
60     uint32_t GetFlags() const override;
GetSurfaceTransformFlags()61     SurfaceTransformFlags GetSurfaceTransformFlags() const override
62     {
63         return 0U; // nothing should be done
64     }
65     uint64_t GetSurfaceHandle() const override;
66 
67     uint32_t GetNextImage() const;
68 
69 private:
70     DeviceGLES& device_;
71 
72     GpuImageDesc desc_ {};
73     GpuImageDesc descDepthBuffer_ {};
74     SwapchainPlatformDataGL plat_ {};
75     uint32_t flags_ { 0u };
76     bool ownsSurface_ { false };
77 };
78 RENDER_END_NAMESPACE()
79 
80 #endif // GLES_SWAPCHAIN_GLES_H
81