1 /* 2 * Copyright (c) 2021-2022 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 SURFACE_READER_H 17 #define SURFACE_READER_H 18 19 #include "refbase.h" 20 21 #include <surface.h> 22 23 #include "surface_reader_handler.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 class SurfaceReader { 28 public: 29 SurfaceReader(); 30 virtual ~SurfaceReader(); 31 32 bool Init(); 33 void DeInit(); 34 35 sptr<Surface> GetSurface() const; 36 void SetHandler(sptr<SurfaceReaderHandler> handler); 37 private: 38 class BufferListener : public IBufferConsumerListener { 39 public: BufferListener(SurfaceReader & surfaceReader)40 explicit BufferListener(SurfaceReader &surfaceReader): surfaceReader_(surfaceReader) 41 { 42 } 43 ~BufferListener() noexcept override = default; OnBufferAvailable()44 void OnBufferAvailable() override 45 { 46 surfaceReader_.OnVsync(); 47 } 48 49 private: 50 SurfaceReader &surfaceReader_; 51 }; 52 friend class BufferListener; 53 54 void OnVsync(); 55 bool ProcessBuffer(const sptr<SurfaceBuffer> &buf); 56 57 sptr<IBufferConsumerListener> listener_ = nullptr; 58 sptr<Surface> csurface_ = nullptr; // cosumer surface 59 sptr<Surface> psurface_ = nullptr; // producer surface 60 sptr<SurfaceBuffer> prevBuffer_ = nullptr; 61 sptr<SurfaceReaderHandler> handler_ = nullptr; 62 }; 63 } 64 } 65 66 #endif // SURFACE_READER_H 67