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 HDI_BACKEND_HDI_FRAMEBUFFER_SURFACE_H 17 #define HDI_BACKEND_HDI_FRAMEBUFFER_SURFACE_H 18 19 #include <refbase.h> 20 21 #include <surface.h> 22 #include <local_semaphore.h> 23 #include <sync_fence.h> 24 25 namespace OHOS { 26 namespace Rosen { 27 28 class HdiFramebufferSurface : public IBufferConsumerListener { 29 public: 30 static sptr<HdiFramebufferSurface> CreateFramebufferSurface(); 31 sptr<OHOS::Surface> GetProducerSurface(); 32 sptr<OHOS::SurfaceBuffer> GetFramebuffer(); 33 sptr<SyncFence> GetFramebufferFence(); 34 int32_t ReleaseFramebuffer(const sptr<SyncFence> &releaseFence); 35 void FramebufferSemWait(); 36 37 private: 38 sptr<OHOS::Surface> consumerSurface_ = nullptr; 39 sptr<OHOS::Surface> producerSurface_ = nullptr; 40 sptr<OHOS::SurfaceBuffer> currentBuffer_ = nullptr; 41 sptr<OHOS::SurfaceBuffer> oldBuffer_ = nullptr; 42 sptr<SyncFence> fbAcquireFence_ = SyncFence::INVALID_FENCE; 43 static constexpr uint32_t MAX_BUFFER_SIZE = 3; 44 LocalSemaphore framebufferSem_; 45 46 HdiFramebufferSurface(); 47 virtual ~HdiFramebufferSurface(); 48 49 void OnBufferAvailable() override; 50 OHOS::SurfaceError SetBufferQueueSize(uint32_t bufferSize); 51 OHOS::SurfaceError CreateSurface(sptr<HdiFramebufferSurface> &fbSurface); 52 }; 53 } // namespace Rosen 54 } // namespace OHOS 55 56 #endif // HDI_BACKEND_HDI_FRAMEBUFFER_SURFACE_H 57