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 #include "surface_reader_handler_impl.h" 17 #include "window_manager_hilog.h" 18 19 namespace OHOS::Rosen { 20 namespace { 21 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SurfaceReaderHandlerImpl"}; 22 } // namespace OnImageAvailable(sptr<Media::PixelMap> pixelMap)23bool SurfaceReaderHandlerImpl::OnImageAvailable(sptr<Media::PixelMap> pixelMap) 24 { 25 std::lock_guard<std::recursive_mutex> lock(mutex_); 26 if (!flag_) { 27 flag_ = true; 28 pixelMap_ = pixelMap; 29 WLOGI("Get an Image!"); 30 } 31 return true; 32 } 33 IsImageOk()34bool SurfaceReaderHandlerImpl::IsImageOk() 35 { 36 std::lock_guard<std::recursive_mutex> lock(mutex_); 37 return flag_; 38 } 39 ResetFlag()40void SurfaceReaderHandlerImpl::ResetFlag() 41 { 42 std::lock_guard<std::recursive_mutex> lock(mutex_); 43 if (flag_) { 44 flag_ = false; 45 } 46 } 47 GetPixelMap()48sptr<Media::PixelMap> SurfaceReaderHandlerImpl::GetPixelMap() 49 { 50 std::lock_guard<std::recursive_mutex> lock(mutex_); 51 return pixelMap_; 52 } 53 } // namespace OHOS::Rosen