1 /* 2 * Copyright (c) 2021-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 HISTREAMER_PLUGINS_COMMON_SURFACE_MEMORY_H 17 #define HISTREAMER_PLUGINS_COMMON_SURFACE_MEMORY_H 18 19 #if !defined(OHOS_LITE) && defined(VIDEO_SUPPORT) 20 21 #include "osal/task/task.h" 22 #include "osal/task/mutex.h" 23 #include "plugin/plugin_buffer.h" 24 #include "common/surface_allocator.h" 25 #include "refbase.h" 26 #include "surface/surface.h" 27 28 namespace OHOS { 29 namespace Media { 30 namespace Plugins { 31 class SurfaceMemory : public Memory { 32 public: 33 ~SurfaceMemory(); 34 35 sptr<SurfaceBuffer> GetSurfaceBuffer(); 36 37 int32_t GetFlushFence(); 38 39 BufferHandle *GetBufferHandle(); 40 41 uint32_t GetSurfaceBufferStride(); 42 43 void SetNeedRender(bool needRender); 44 45 protected: 46 uint8_t* GetRealAddr() const override; 47 48 private: 49 explicit SurfaceMemory(size_t capacity, std::shared_ptr<Allocator> allocator = nullptr, size_t align = 1); 50 explicit SurfaceMemory(sptr<SurfaceBuffer> surfaceBuffer, int32_t surfaceCapacity); 51 52 void AllocSurfaceBuffer(); 53 void ReleaseSurfaceBuffer(); 54 55 mutable Mutex memMutex_ {}; 56 57 /// Surface buffer 58 sptr<SurfaceBuffer> surfaceBuffer_ {nullptr}; 59 60 std::shared_ptr<SurfaceAllocator> surfaceAllocator_ {nullptr}; 61 62 /// the fence fd for Surface 63 int32_t fence_ {-1}; 64 65 uint32_t stride_ {0}; 66 67 bool needRender_ {false}; 68 69 friend class Buffer; 70 }; 71 } // namespace Plugins 72 } // namespace Media 73 } // namespace OHOS 74 75 #endif 76 #endif // HISTREAMER_PLUGINS_COMMON_SURFACE_MEMORY_H 77