132a6e48fSopenharmony_ci/* 232a6e48fSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 332a6e48fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 432a6e48fSopenharmony_ci * you may not use this file except in compliance with the License. 532a6e48fSopenharmony_ci * You may obtain a copy of the License at 632a6e48fSopenharmony_ci * 732a6e48fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 832a6e48fSopenharmony_ci * 932a6e48fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1032a6e48fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1132a6e48fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1232a6e48fSopenharmony_ci * See the License for the specific language governing permissions and 1332a6e48fSopenharmony_ci * limitations under the License. 1432a6e48fSopenharmony_ci */ 1532a6e48fSopenharmony_ci 1632a6e48fSopenharmony_ci#ifndef FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_CONSUMER_H 1732a6e48fSopenharmony_ci#define FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_CONSUMER_H 1832a6e48fSopenharmony_ci 1932a6e48fSopenharmony_ci#include <refbase.h> 2032a6e48fSopenharmony_ci 2132a6e48fSopenharmony_ci#include "surface_type.h" 2232a6e48fSopenharmony_ci#include "surface_buffer.h" 2332a6e48fSopenharmony_ci#include "buffer_queue.h" 2432a6e48fSopenharmony_ci 2532a6e48fSopenharmony_cinamespace OHOS { 2632a6e48fSopenharmony_ciclass BufferQueueConsumer : public RefBase { 2732a6e48fSopenharmony_cipublic: 2832a6e48fSopenharmony_ci BufferQueueConsumer(sptr<BufferQueue>& bufferQueue); 2932a6e48fSopenharmony_ci virtual ~BufferQueueConsumer(); 3032a6e48fSopenharmony_ci 3132a6e48fSopenharmony_ci GSError AcquireBuffer(sptr<SurfaceBuffer> &buffer, sptr<SyncFence> &fence, 3232a6e48fSopenharmony_ci int64_t ×tamp, std::vector<Rect> &damages); 3332a6e48fSopenharmony_ci GSError AcquireBuffer(IConsumerSurface::AcquireBufferReturnValue &returnValue, int64_t expectPresentTimestamp, 3432a6e48fSopenharmony_ci bool isUsingAutoTimestamp); 3532a6e48fSopenharmony_ci GSError ReleaseBuffer(sptr<SurfaceBuffer>& buffer, const sptr<SyncFence>& fence); 3632a6e48fSopenharmony_ci 3732a6e48fSopenharmony_ci GSError AttachBuffer(sptr<SurfaceBuffer>& buffer); 3832a6e48fSopenharmony_ci GSError AttachBuffer(sptr<SurfaceBuffer>& buffer, int32_t timeOut); 3932a6e48fSopenharmony_ci 4032a6e48fSopenharmony_ci GSError DetachBuffer(sptr<SurfaceBuffer>& buffer); 4132a6e48fSopenharmony_ci GSError RegisterSurfaceDelegator(sptr<IRemoteObject> client, sptr<Surface> cSurface); 4232a6e48fSopenharmony_ci 4332a6e48fSopenharmony_ci bool QueryIfBufferAvailable(); 4432a6e48fSopenharmony_ci 4532a6e48fSopenharmony_ci GSError RegisterConsumerListener(sptr<IBufferConsumerListener>& listener); 4632a6e48fSopenharmony_ci GSError RegisterConsumerListener(IBufferConsumerListenerClazz *listener); 4732a6e48fSopenharmony_ci GSError RegisterReleaseListener(OnReleaseFunc func); 4832a6e48fSopenharmony_ci GSError RegisterDeleteBufferListener(OnDeleteBufferFunc func, bool isForUniRedraw = false); 4932a6e48fSopenharmony_ci GSError UnregisterConsumerListener(); 5032a6e48fSopenharmony_ci 5132a6e48fSopenharmony_ci GSError SetDefaultWidthAndHeight(int32_t width, int32_t height); 5232a6e48fSopenharmony_ci GSError SetDefaultUsage(uint64_t usage); 5332a6e48fSopenharmony_ci void Dump(std::string &result) const; 5432a6e48fSopenharmony_ci GraphicTransformType GetTransform() const; 5532a6e48fSopenharmony_ci GSError GetScalingMode(uint32_t sequence, ScalingMode &scalingMode) const; 5632a6e48fSopenharmony_ci GSError QueryMetaDataType(uint32_t sequence, HDRMetaDataType &type) const; 5732a6e48fSopenharmony_ci GSError GetMetaData(uint32_t sequence, std::vector<GraphicHDRMetaData> &metaData) const; 5832a6e48fSopenharmony_ci GSError GetMetaDataSet(uint32_t sequence, GraphicHDRMetadataKey &key, std::vector<uint8_t> &metaData) const; 5932a6e48fSopenharmony_ci GSError GetGlobalAlpha(int32_t &alpha); 6032a6e48fSopenharmony_ci sptr<SurfaceTunnelHandle> GetTunnelHandle() const; 6132a6e48fSopenharmony_ci GSError SetPresentTimestamp(uint32_t sequence, const GraphicPresentTimestamp ×tamp); 6232a6e48fSopenharmony_ci 6332a6e48fSopenharmony_ci bool GetStatus() const; 6432a6e48fSopenharmony_ci void SetStatus(bool status); 6532a6e48fSopenharmony_ci GSError OnConsumerDied(); 6632a6e48fSopenharmony_ci GSError GoBackground(); 6732a6e48fSopenharmony_ci void ConsumerRequestCpuAccess(bool on) 6832a6e48fSopenharmony_ci { 6932a6e48fSopenharmony_ci bufferQueue_->ConsumerRequestCpuAccess(on); 7032a6e48fSopenharmony_ci } 7132a6e48fSopenharmony_ci 7232a6e48fSopenharmony_ci GSError AttachBufferToQueue(sptr<SurfaceBuffer> buffer); 7332a6e48fSopenharmony_ci GSError DetachBufferFromQueue(sptr<SurfaceBuffer> buffer); 7432a6e48fSopenharmony_ci void SetBufferHold(bool hold); 7532a6e48fSopenharmony_ci inline bool IsBufferHold() 7632a6e48fSopenharmony_ci { 7732a6e48fSopenharmony_ci if (bufferQueue_ == nullptr) { 7832a6e48fSopenharmony_ci return false; 7932a6e48fSopenharmony_ci } 8032a6e48fSopenharmony_ci return bufferQueue_->IsBufferHold(); 8132a6e48fSopenharmony_ci } 8232a6e48fSopenharmony_ci float GetHdrWhitePointBrightness() const; 8332a6e48fSopenharmony_ci float GetSdrWhitePointBrightness() const; 8432a6e48fSopenharmony_ci GSError IsSurfaceBufferInCache(uint32_t seqNum, bool &isInCache); 8532a6e48fSopenharmony_ci uint32_t GetAvailableBufferCount() const; 8632a6e48fSopenharmony_ciprivate: 8732a6e48fSopenharmony_ci sptr<BufferQueue> bufferQueue_ = nullptr; 8832a6e48fSopenharmony_ci std::string name_ = "not init"; 8932a6e48fSopenharmony_ci}; 9032a6e48fSopenharmony_ci} // namespace OHOS 9132a6e48fSopenharmony_ci 9232a6e48fSopenharmony_ci#endif // FRAMEWORKS_SURFACE_INCLUDE_BUFFER_QUEUE_CONSUMER_H 93