• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FRAMEWORKS_INNERKITSIMPL_EGL_IMAGE_INCLUDE_PIXELMAP_GL_POST_PROC_PROGRAM_H
17 #define FRAMEWORKS_INNERKITSIMPL_EGL_IMAGE_INCLUDE_PIXELMAP_GL_POST_PROC_PROGRAM_H
18 
19 #include <iostream>
20 #include <mutex>
21 #include <array>
22 #include <atomic>
23 #include <condition_variable>
24 #include <numeric>
25 #include "pixel_map_gl_shader.h"
26 #include "surface_buffer.h"
27 #include "surface_utils.h"
28 #include "window.h"
29 
30 #define EXPORT __attribute__ ((visibility ("default")))
31 
32 namespace OHOS {
33 namespace Media {
34 using namespace std;
35 
36 class PixelMapGLPostProcProgram {
37 public:
38     PixelMapGLPostProcProgram();
39     ~PixelMapGLPostProcProgram() noexcept;
40     PixelMapGLPostProcProgram(const PixelMapGLPostProcProgram &) = delete;
41     void operator=(const PixelMapGLPostProcProgram &) = delete;
42     PixelMapGLPostProcProgram(const PixelMapGLPostProcProgram &&) = delete;
43     void operator=(const PixelMapGLPostProcProgram &&) = delete;
44 
45     bool Init();
46     bool GenProcEndData(char *lcdData);
47     bool GenProcDmaEndData(void *surfaceBuffer);
48     bool Execute();
49     void SetGPUTransformData(GPUTransformData &transformData);
50 
51     static bool BuildShader();
52 
53 private:
54     static void DestoryInstanceThreadFunc();
55     bool GLMakecurrent(bool needCurrent);
56     bool InitGLResource();
57     bool BuildVertex();
58     bool CreateEGLImage(OHNativeWindowBuffer *nativeBuffer, EGLImageKHR &eglImage, GLuint &imageTexId);
59     bool UseEGLImageCreateNormalImage(GLuint &imageTexId);
60     bool CreateNormalImage(const uint8_t *data, GLuint &imageTexId);
61     bool BuildProcTexture(bool needThumb, bool needUpload, GLuint &readTexId);
62     bool BuildTargetTexture();
63     void DestroyProcTexture();
64     bool ResizeRotateWithGL();
65     bool ResizeScaleWithGL();
66     bool ReadEndData(char *targetData, GLuint &writeTexId);
67     bool ReadEndDMAData(void *surfaceBuffer, GLuint &writeTexId);
68     void Clear() noexcept;
69 
70 private:
71     unique_ptr<PixelMapGlContext> renderContext_;
72     std::shared_ptr<PixelMapGlShader::Shader> rotateShader_ = nullptr;
73     std::shared_ptr<PixelMapGlShader::Shader> slrShader_ = nullptr;
74     std::shared_ptr<PixelMapGlShader::Shader> lapShader_ = nullptr;
75     std::shared_ptr<PixelMapGlShader::Shader> vertexShader_ = nullptr;
76 
77     EGLImageKHR eglImage_ = EGL_NO_IMAGE_KHR;
78     GPUTransformData transformData_;
79 };
80 } // namespace Media
81 } // namespace OHOS
82 
83 #endif // FRAMEWORKS_INNERKITSIMPL_EGL_IMAGE_INCLUDE_PIXELMAP_GL_POST_PROC_PROGRAM_H
84