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 RENDER_DEFAULT_DATA_H 17 #define RENDER_DEFAULT_DATA_H 18 19 #include "base/render_base.h" 20 21 namespace OHOS { 22 namespace Media { 23 namespace Effect { 24 constexpr const int RGBA_SIZE_PER_PIXEL = 4; 25 26 const std::vector<std::vector<float>> DEFAULT_VERTEX_DATA = { { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, -1.0f, 1.0f, 27 0.0f, 1.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f } }; 28 const std::vector<std::vector<float>> DEFAULT_FLIP_VERTEX_DATA = { { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, -1.0f, 29 1.0f, 0.0f, 1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f } }; 30 31 constexpr const char *DEFAULT_VERTEX_SHADER_SCREEN_CODE = "attribute vec4 aPosition;\n" 32 "attribute vec4 aTextureCoord;\n" 33 "varying vec2 textureCoordinate;\n" 34 35 "void main()\n" 36 "{\n" 37 " gl_Position = aPosition;\n" 38 " textureCoordinate = aTextureCoord.xy;\n" 39 "}\n"; 40 41 constexpr const char *TRANSFORM_VERTEX_SHADER_SCREEN_CODE = "attribute vec4 aPosition;\n" 42 "attribute vec4 aTextureCoord;\n" 43 "varying vec2 textureCoordinate;\n" 44 "uniform mat4 transform;\n" 45 46 "void main()\n" 47 "{\n" 48 " gl_Position = transform * aPosition;\n" 49 " textureCoordinate = aTextureCoord.xy;\n" 50 "}\n"; 51 52 constexpr const char *DEFAULT_YUV_VERTEX_SHADER = "#version 310 es\n" 53 "precision highp float;\n" 54 "layout (location = 0) in vec3 aPosition;\n" 55 "layout (location = 1) in vec2 aTextureCoord;\n" 56 "out vec2 textureCoordinate;\n" 57 "void main()\n" 58 "{\n" 59 " gl_Position = vec4(aPosition, 1.0);\n" 60 " textureCoordinate = aTextureCoord.xy;\n" 61 "}\n"; 62 63 constexpr const char *TRANSFORM_YUV_VERTEX_SHADER = "#version 310 es\n" 64 "precision highp float;\n" 65 "layout (location = 0) in vec3 aPosition;\n" 66 "layout (location = 1) in vec2 aTextureCoord;\n" 67 "out vec2 textureCoordinate;\n" 68 "uniform mat4 transform;\n" 69 "uniform float flipH;\n" 70 "uniform float flipV;\n" 71 "void main()\n" 72 "{\n" 73 " gl_Position = transform * vec4(aPosition, 1.0);\n" 74 " if (flipH > 0.0) {\n" 75 " textureCoordinate = vec2(1.0 - aTextureCoord.x, aTextureCoord.y);\n" 76 " } else if (flipV > 0.0) {\n" 77 " textureCoordinate = vec2(aTextureCoord.x, 1.0 - aTextureCoord.y);\n" 78 " } else {\n" 79 " textureCoordinate = aTextureCoord.xy;\n" 80 " }\n" 81 "}\n"; 82 83 constexpr const char *DEFAULT_YUV_SHADER_CODE = "#version 310 es\n" 84 "#extension GL_EXT_YUV_target : require\n" 85 "#extension GL_OES_EGL_image_external_essl3 : require\n" 86 "precision highp float;\n" 87 "uniform samplerExternalOES yuv_img_tex;\n" 88 "in vec2 textureCoordinate;\n" 89 "layout(yuv) out vec4 v_out_color;\n" 90 "void main()\n" 91 "{\n" 92 " vec4 inputrgb = texture(yuv_img_tex, textureCoordinate).rgba;\n" 93 " v_out_color = vec4(rgb_2_yuv(inputrgb.rgb, itu_601), 1.0);\n" 94 "}\n"; 95 96 constexpr const char *DEFAULT_YUV_RGBA_SHADER_CODE = "#version 310 es\n" 97 "#extension GL_EXT_YUV_target : require\n" 98 "#extension GL_OES_EGL_image_external_essl3 : require\n" 99 "precision highp float;\n" 100 "uniform samplerExternalOES yuv_img_tex;\n" 101 "in vec2 textureCoordinate;\n" 102 "out vec4 v_out_color;\n" 103 "void main()\n" 104 "{\n" 105 " vec3 inputrgb = texture(yuv_img_tex, textureCoordinate).rgb;\n" 106 " v_out_color = vec4(inputrgb, 1.0);\n" 107 "}\n"; 108 109 constexpr const char *DEFAULT_RGBA_YUV_SHADER_CODE = "#version 310 es\n" 110 "#extension GL_EXT_YUV_target : require\n" 111 "#extension GL_OES_EGL_image_external_essl3 : require\n" 112 "precision highp float;\n" 113 "uniform sampler2D inputTexture;\n" 114 "in vec2 textureCoordinate;\n" 115 "layout(yuv) out vec4 v_out_color;\n" 116 "void main()\n" 117 "{\n" 118 " vec3 inputrgb = texture(inputTexture, textureCoordinate).rgb;\n" 119 " v_out_color = vec4(rgb_2_yuv(inputrgb, itu_601), 1.0);\n" 120 "}\n"; 121 122 constexpr const char *DEFAULT_FRAGMENT_SHADER_CODE = "precision highp float;\n" 123 "varying vec2 textureCoordinate;\n" 124 "uniform sampler2D inputTexture;\n" 125 "void main()\n" 126 "{\n" 127 " gl_FragColor = texture2D(inputTexture, textureCoordinate);\n" 128 "}\n"; 129 130 constexpr const char *DEFAULT_FRAGMENT_BGRA_SHADER_CODE = "precision highp float;\n" 131 "varying vec2 textureCoordinate;\n" 132 "uniform sampler2D inputTexture;\n" 133 "void main()\n" 134 "{\n" 135 " gl_FragColor = texture2D(inputTexture, textureCoordinate).bgra;\n" 136 "}\n"; 137 } // namespace Effect 138 } // namespace Media 139 } // namespace OHOS 140 #endif