1 /* 2 * Copyright (c) 2021 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_SURFACE_INCLUDE_PRODUCER_EGL_SURFACE_H 17 #define FRAMEWORKS_SURFACE_INCLUDE_PRODUCER_EGL_SURFACE_H 18 19 #include <map> 20 #include <string> 21 22 #include <egl_surface.h> 23 #include <ibuffer_producer.h> 24 25 #include "surface_buffer.h" 26 27 namespace OHOS { 28 class ProducerEglSurface : public EglSurface { 29 public: 30 ProducerEglSurface(sptr<IBufferProducer>& producer); 31 virtual ~ProducerEglSurface(); 32 33 GSError InitContext(EGLContext context = EGL_NO_CONTEXT) override; 34 EGLDisplay GetEglDisplay() const override; 35 EGLContext GetEglContext() const override; 36 EGLSurface GetEglSurface() const override; 37 GLuint GetEglFbo() const override; 38 GSError SwapBuffers() override; 39 GSError SetWidthAndHeight(int32_t width, int32_t height) override; 40 41 private: 42 bool IsRemote(); 43 GSError RequestBuffer(sptr<SurfaceBuffer> &buffer, int32_t &fence, BufferRequestConfig &config); 44 45 GSError RequestBufferProc(); 46 GSError FlushBufferProc(); 47 GSError FlushBuffer(sptr<SurfaceBuffer> &buffer, int32_t fence, BufferFlushConfig &config); 48 GSError AddEglData(sptr<SurfaceBuffer> &buffer); 49 GSError CreateEglFenceFd(int32_t &fd); 50 GSError WaitForReleaseFence(int32_t fd); 51 52 std::map<int32_t, sptr<SurfaceBuffer>> bufferProducerCache_; 53 sptr<IBufferProducer> producer_ = nullptr; 54 std::string name_ = "not init"; 55 bool initFlag_ = false; 56 sptr<EglManager> sEglManager_ = nullptr; 57 sptr<SurfaceBuffer> currentBuffer_ = nullptr; 58 std::mutex mutex_; 59 int32_t width_; 60 int32_t height_; 61 }; 62 } // namespace OHOS 63 64 #endif // FRAMEWORKS_SURFACE_INCLUDE_PRODUCER_EGL_SURFACE_H 65