1 /* 2 * Copyright (c) 2023 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 RS_RENDER_SURFACE_FRAME_H 17 #define RS_RENDER_SURFACE_FRAME_H 18 19 #include <EGL/egl.h> 20 #include <surface.h> 21 22 #include "common/rs_rect.h" 23 #include "include/core/SkSurface.h" 24 25 #ifdef RS_ENABLE_VK 26 #include <vulkan_window.h> 27 #endif 28 29 namespace OHOS { 30 namespace Rosen { 31 enum PlatformName { 32 OHOS, 33 ANDROID, 34 IOS, 35 WINDOWS, 36 DARWIN, 37 }; 38 39 enum RenderType { 40 RASTER, 41 GLES, 42 VULKAN, 43 }; 44 45 typedef struct EGLState { EGLStateEGLState46 EGLState() 47 { 48 eglContext = EGL_NO_CONTEXT; 49 eglDisplay = EGL_NO_DISPLAY; 50 eglSurface = EGL_NO_SURFACE; 51 } 52 EGLContext eglContext; 53 EGLDisplay eglDisplay; 54 EGLSurface eglSurface; 55 } EGLState; 56 57 #ifdef RS_ENABLE_VK 58 typedef struct VulkanState { 59 std::shared_ptr<vulkan::VulkanWindow> vulkanWindow; 60 } VulkanState; 61 #endif 62 63 typedef struct FrameConfig { FrameConfigFrameConfig64 FrameConfig() 65 { 66 width = 0; 67 height = 0; 68 uiTimestamp = 0; 69 bpp = 0; 70 releaseFence = -1; 71 pixelFormat = GRAPHIC_PIXEL_FMT_RGBA_8888; 72 bufferUsage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_DMA; 73 useAFBC = false; 74 colorSpace = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB; 75 requestConfig = { 76 .width = 0x100, 77 .height = 0x100, 78 .strideAlignment = 0x8, 79 .format = GRAPHIC_PIXEL_FMT_RGBA_8888, 80 .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA, 81 .timeout = 0, 82 }; 83 flushConfig = { 84 .damage = { 85 .x = 0, 86 .y = 0, 87 .w = 0x100, 88 .h = 0x100, 89 }, 90 }; 91 skSurface = nullptr; 92 buffer = nullptr; 93 } 94 int32_t width; 95 int32_t height; 96 uint64_t uiTimestamp; 97 int32_t bpp; 98 int32_t releaseFence; 99 int32_t pixelFormat; 100 uint64_t bufferUsage; 101 bool useAFBC; 102 GraphicColorGamut colorSpace; 103 std::vector<RectI> damageRects; 104 std::unique_ptr<uint32_t[]> addr; 105 BufferRequestConfig requestConfig; 106 BufferFlushConfig flushConfig; 107 sptr<SurfaceBuffer> buffer; 108 sk_sp<SkSurface> skSurface; 109 } FrameConfig; 110 111 typedef struct SurfaceConfig { 112 sptr<Surface> producer; 113 struct NativeWindow* nativeWindow; 114 } SurfaceConfig; 115 116 typedef struct RSRenderSurfaceFrame { 117 std::shared_ptr<SurfaceConfig> surfaceConfig; 118 std::shared_ptr<FrameConfig> frameConfig; 119 std::shared_ptr<EGLState> eglState; 120 #if defined(RS_ENABLE_VK) 121 std::shared_ptr<VulkanState> vulkanState; 122 #endif 123 } RSRenderSurfaceFrame; 124 } 125 } 126 #endif