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 #include "render/rs_shadow.h" 17 18 #include <algorithm> 19 20 namespace OHOS { 21 namespace Rosen { RSShadow()22RSShadow::RSShadow() {} 23 ~RSShadow()24RSShadow::~RSShadow() {} 25 SetColor(Color color)26void RSShadow::SetColor(Color color) 27 { 28 color_ = color; 29 } 30 SetOffsetX(float offsetX)31void RSShadow::SetOffsetX(float offsetX) 32 { 33 offsetX_ = offsetX; 34 } 35 SetOffsetY(float offsetY)36void RSShadow::SetOffsetY(float offsetY) 37 { 38 offsetY_ = offsetY; 39 } 40 SetAlpha(float alpha)41void RSShadow::SetAlpha(float alpha) 42 { 43 color_.SetAlpha(std::clamp(alpha, 0.0f, 1.0f) * UINT8_MAX); 44 } 45 SetElevation(float elevation)46void RSShadow::SetElevation(float elevation) 47 { 48 isHardwareAcceleration_ = true; 49 elevation_ = elevation; 50 } 51 SetRadius(float radius)52void RSShadow::SetRadius(float radius) 53 { 54 isHardwareAcceleration_ = false; 55 radius_ = radius; 56 } 57 SetPath(const std::shared_ptr<RSPath> & path)58void RSShadow::SetPath(const std::shared_ptr<RSPath>& path) 59 { 60 path_ = path; 61 } 62 SetMask(bool mask)63void RSShadow::SetMask(bool mask) 64 { 65 imageMask_ = mask; 66 } 67 GetColor() const68Color RSShadow::GetColor() const 69 { 70 return color_; 71 } 72 GetOffsetX() const73float RSShadow::GetOffsetX() const 74 { 75 return offsetX_; 76 } 77 GetOffsetY() const78float RSShadow::GetOffsetY() const 79 { 80 return offsetY_; 81 } 82 GetAlpha() const83float RSShadow::GetAlpha() const 84 { 85 return static_cast<float>(color_.GetAlpha()) / UINT8_MAX; 86 } 87 GetElevation() const88float RSShadow::GetElevation() const 89 { 90 return elevation_; 91 } 92 GetRadius() const93float RSShadow::GetRadius() const 94 { 95 return radius_; 96 } 97 GetPath() const98const std::shared_ptr<RSPath>& RSShadow::GetPath() const 99 { 100 return path_; 101 } 102 GetMask() const103bool RSShadow::GetMask() const 104 { 105 return imageMask_; 106 } 107 IsValid() const108bool RSShadow::IsValid() const 109 { 110 if (isHardwareAcceleration_) { 111 return GetAlpha() > 0.f; 112 } else { 113 return radius_ > 0.f; 114 } 115 } 116 } // namespace Rosen 117 } // namespace OHOS 118