1 /* 2 * Copyright (c) 2023-2023 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 BRRIGHTNESS_DIMMING_H 17 #define BRRIGHTNESS_DIMMING_H 18 19 #include <atomic> 20 #include <cstdint> 21 #include <event_handler.h> 22 #include <event_runner.h> 23 #include "ffrt_utils.h" 24 #include <iosfwd> 25 #include <memory> 26 #include <string> 27 28 #include "brightness_dimming_callback.h" 29 #include "inner_event.h" 30 31 namespace OHOS { 32 namespace DisplayPowerMgr { 33 class BrightnessDimming : public std::enable_shared_from_this<BrightnessDimming> { 34 public: 35 BrightnessDimming(const std::string& name, std::shared_ptr<BrightnessDimmingCallback>& callback); 36 virtual ~BrightnessDimming() = default; 37 BrightnessDimming(const BrightnessDimming&) = delete; 38 BrightnessDimming& operator=(const BrightnessDimming&) = delete; 39 BrightnessDimming(BrightnessDimming&&) = delete; 40 BrightnessDimming& operator=(BrightnessDimming&&) = delete; 41 42 void StartDimming(uint32_t from, uint32_t to, uint32_t duration); 43 void StopDimming(); 44 bool IsDimming() const; 45 uint32_t GetDimmingUpdateTime() const; 46 bool Init(); 47 void Reset(); 48 private: 49 static const uint32_t DEFAULT_UPDATE_TIME = 32; 50 static const int32_t STRIDE_ABSOLUTE_MIN = 1; 51 52 void NextStep(); 53 54 std::string mName{}; 55 std::shared_ptr<BrightnessDimmingCallback> mCallback{}; 56 std::atomic_bool mDimming{}; 57 std::atomic_uint32_t mFromBrightness{}; 58 std::atomic_uint32_t mToBrightness{}; 59 std::atomic_uint32_t mDuration{}; 60 std::atomic_uint32_t mUpdateTime{}; 61 std::atomic_uint32_t mTotalSteps{}; 62 std::atomic_int32_t mStride{}; 63 std::atomic_uint32_t mCurrentBrightness{}; 64 std::atomic_uint32_t mCurrentStep{}; 65 std::shared_ptr<PowerMgr::FFRTQueue> mQueue; 66 }; 67 } // namespace DisplayPowerMgr 68 } // namespace OHOS 69 #endif // BRRIGHTNESS_DIMMING_H