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_WM_INCLUDE_WL_BUFFER_CACHE_H 17 #define FRAMEWORKS_WM_INCLUDE_WL_BUFFER_CACHE_H 18 19 #include <refbase.h> 20 #include <surface.h> 21 22 #include <window_manager_type.h> 23 24 #include "singleton_delegator.h" 25 #include "wl_buffer.h" 26 #include "wl_display.h" 27 28 namespace OHOS { 29 class WlBufferCache : public RefBase { 30 public: 31 static sptr<WlBufferCache> GetInstance(); 32 33 MOCKABLE void Init(); 34 MOCKABLE void Deinit(); 35 36 MOCKABLE sptr<WlBuffer> GetWlBuffer(const sptr<Surface> &csurf, 37 const sptr<SurfaceBuffer> &buffer); 38 39 MOCKABLE GSError AddWlBuffer(const sptr<WlBuffer> &wbuffer, 40 const sptr<Surface> &csurf, 41 const sptr<SurfaceBuffer> &sbuffer); 42 43 MOCKABLE bool GetSurfaceBuffer(const struct wl_buffer *wbuffer, 44 sptr<Surface> &surf, 45 sptr<SurfaceBuffer> &sbuffer); 46 47 MOCKABLE void CleanCache(); 48 49 private: 50 WlBufferCache() = default; 51 MOCKABLE ~WlBufferCache() = default; 52 static inline sptr<WlBufferCache> instance = nullptr; 53 static inline SingletonDelegator<WlBufferCache> delegator; 54 55 struct BufferCache { 56 sptr<WlBuffer> wbuffer; 57 wptr<Surface> csurf; 58 wptr<SurfaceBuffer> sbuffer; 59 }; 60 std::vector<WlBufferCache::BufferCache> cache; 61 std::mutex cacheMutex; 62 }; 63 } // namespace OHOS 64 65 #endif // FRAMEWORKS_WM_INCLUDE_WL_BUFFER_CACHE_H 66