1 /* 2 * Copyright (c) 2024 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 17 #include "info_collection/rs_hdr_collection.h" 18 19 #include <chrono> 20 21 namespace OHOS { 22 namespace Rosen { 23 RsHdrCollection()24RsHdrCollection::RsHdrCollection() {} ~RsHdrCollection()25RsHdrCollection::~RsHdrCollection() {} 26 HandleHdrState(bool isHdrOn)27void RsHdrCollection::HandleHdrState(bool isHdrOn) 28 { 29 std::lock_guard<std::mutex> lock(hdrOnDurationMtx_); 30 if (isHdrOn_ != isHdrOn) { 31 isHdrOn_ = isHdrOn; 32 if (isHdrOn_) { 33 hdrOnTimestamp_ = GetSysTimeMs(); 34 } else { 35 int64_t now = GetSysTimeMs(); 36 hdrOnDuration_ += now > hdrOnTimestamp_ ? now - hdrOnTimestamp_ : 0; 37 } 38 } 39 } 40 ResetHdrOnDuration()41void RsHdrCollection::ResetHdrOnDuration() 42 { 43 std::lock_guard<std::mutex> lock(hdrOnDurationMtx_); 44 hdrOnDuration_ = 0; 45 } 46 GetHdrOnDuration()47int64_t RsHdrCollection::GetHdrOnDuration() 48 { 49 std::lock_guard<std::mutex> lock(hdrOnDurationMtx_); 50 return hdrOnDuration_; 51 } 52 GetSysTimeMs()53int64_t RsHdrCollection::GetSysTimeMs() 54 { 55 auto now = std::chrono::steady_clock::now().time_since_epoch(); 56 return static_cast<int64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(now).count()); 57 } 58 } // namespace Rosen 59 } // namespace OHOS 60