18bf80f4bSopenharmony_ci/*
28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License.
58bf80f4bSopenharmony_ci * You may obtain a copy of the License at
68bf80f4bSopenharmony_ci *
78bf80f4bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88bf80f4bSopenharmony_ci *
98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and
138bf80f4bSopenharmony_ci * limitations under the License.
148bf80f4bSopenharmony_ci */
158bf80f4bSopenharmony_ci
168bf80f4bSopenharmony_ci#ifndef GLES_SWAPCHAIN_GLES_H
178bf80f4bSopenharmony_ci#define GLES_SWAPCHAIN_GLES_H
188bf80f4bSopenharmony_ci
198bf80f4bSopenharmony_ci#include <cstdint>
208bf80f4bSopenharmony_ci
218bf80f4bSopenharmony_ci#include <base/containers/vector.h>
228bf80f4bSopenharmony_ci#include <render/device/gpu_resource_desc.h>
238bf80f4bSopenharmony_ci#include <render/namespace.h>
248bf80f4bSopenharmony_ci
258bf80f4bSopenharmony_ci#include "device/swapchain.h"
268bf80f4bSopenharmony_ci#include "gles/gpu_image_gles.h"
278bf80f4bSopenharmony_ci
288bf80f4bSopenharmony_ciRENDER_BEGIN_NAMESPACE()
298bf80f4bSopenharmony_ciclass Device;
308bf80f4bSopenharmony_ciclass DeviceGLES;
318bf80f4bSopenharmony_cistruct SwapchainCreateInfo;
328bf80f4bSopenharmony_ci
338bf80f4bSopenharmony_cistruct SwapchainImagesGLES {
348bf80f4bSopenharmony_ci    BASE_NS::vector<uint32_t> images;
358bf80f4bSopenharmony_ci
368bf80f4bSopenharmony_ci    uint32_t width { 0 };
378bf80f4bSopenharmony_ci    uint32_t height { 0 };
388bf80f4bSopenharmony_ci};
398bf80f4bSopenharmony_ci
408bf80f4bSopenharmony_cistruct SwapchainPlatformDataGL final {
418bf80f4bSopenharmony_ci    uintptr_t surface; // currently EGLSurface (on GLES) or HDC (on GL/Windows)
428bf80f4bSopenharmony_ci#if RENDER_GL_FLIP_Y_SWAPCHAIN
438bf80f4bSopenharmony_ci    BASE_NS::vector<uint32_t> fbos; // FBO for the swapchain.
448bf80f4bSopenharmony_ci#endif
458bf80f4bSopenharmony_ci    uint32_t swapchainImageIndex;
468bf80f4bSopenharmony_ci    SwapchainImagesGLES swapchainImages;
478bf80f4bSopenharmony_ci    bool vsync;
488bf80f4bSopenharmony_ci    GpuImagePlatformDataGL depthPlatformData;
498bf80f4bSopenharmony_ci};
508bf80f4bSopenharmony_ci
518bf80f4bSopenharmony_ciclass SwapchainGLES final : public Swapchain {
528bf80f4bSopenharmony_cipublic:
538bf80f4bSopenharmony_ci    SwapchainGLES(Device& device, const SwapchainCreateInfo& swapchainCreateInfo);
548bf80f4bSopenharmony_ci    ~SwapchainGLES() override;
558bf80f4bSopenharmony_ci
568bf80f4bSopenharmony_ci    const SwapchainPlatformDataGL& GetPlatformData() const;
578bf80f4bSopenharmony_ci    const GpuImageDesc& GetDesc() const override;
588bf80f4bSopenharmony_ci    const GpuImageDesc& GetDescDepthBuffer() const override;
598bf80f4bSopenharmony_ci
608bf80f4bSopenharmony_ci    uint32_t GetFlags() const override;
618bf80f4bSopenharmony_ci    SurfaceTransformFlags GetSurfaceTransformFlags() const override
628bf80f4bSopenharmony_ci    {
638bf80f4bSopenharmony_ci        return 0U; // nothing should be done
648bf80f4bSopenharmony_ci    }
658bf80f4bSopenharmony_ci    uint64_t GetSurfaceHandle() const override;
668bf80f4bSopenharmony_ci
678bf80f4bSopenharmony_ci    uint32_t GetNextImage() const;
688bf80f4bSopenharmony_ci
698bf80f4bSopenharmony_ciprivate:
708bf80f4bSopenharmony_ci    DeviceGLES& device_;
718bf80f4bSopenharmony_ci
728bf80f4bSopenharmony_ci    GpuImageDesc desc_ {};
738bf80f4bSopenharmony_ci    GpuImageDesc descDepthBuffer_ {};
748bf80f4bSopenharmony_ci    SwapchainPlatformDataGL plat_ {};
758bf80f4bSopenharmony_ci    uint32_t flags_ { 0u };
768bf80f4bSopenharmony_ci    bool ownsSurface_ { false };
778bf80f4bSopenharmony_ci};
788bf80f4bSopenharmony_ciRENDER_END_NAMESPACE()
798bf80f4bSopenharmony_ci
808bf80f4bSopenharmony_ci#endif // GLES_SWAPCHAIN_GLES_H
81