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 RENDER_SERVICE_CLIENT_CORE_RENDER_RS_SHADOW_H 17 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_SHADOW_H 18 19 #include <memory> 20 21 #include "common/rs_color.h" 22 #include "common/rs_macros.h" 23 #include "render/rs_path.h" 24 namespace OHOS { 25 namespace Rosen { 26 const float DEFAULT_LIGHT_POSITION_X = 540.0f; 27 const float DEFAULT_LIGHT_POSITION_Y = 0.0f; 28 const float DEFAULT_LIGHT_HEIGHT = 600.0f; 29 const float DEFAULT_LIGHT_RADIUS = 800.0f; 30 const float DEFAULT_SHADOW_OFFSET_X = 0.f; 31 const float DEFAULT_SHADOW_OFFSET_Y = 0.f; 32 const float DEFAULT_SHADOW_RADIUS = 0.f; 33 const float DEFAULT_TRANSLATION_Z = 300.0f; 34 const uint32_t DEFAULT_AMBIENT_COLOR = 0x0A000000; 35 const uint32_t DEFAULT_SPOT_COLOR = 0x00000000; 36 37 enum SHADOW_COLOR_STRATEGY : int { 38 COLOR_STRATEGY_NONE = 0, // use pre-defined shadow color 39 COLOR_STRATEGY_AVERAGE = 1, // use average color of the shadow area 40 COLOR_STRATEGY_MAIN = 2, // use main color of the shadow area 41 }; 42 43 class RSShadow { 44 public: 45 RSShadow(); 46 virtual ~RSShadow(); 47 void SetColor(Color color); 48 void SetOffsetX(float offsetX); 49 void SetOffsetY(float offsetY); 50 void SetAlpha(float alpha); 51 void SetElevation(float elevation); 52 void SetRadius(float radius); 53 void SetPath(const std::shared_ptr<RSPath>& path); 54 void SetMask(bool imageMask); 55 void SetIsFilled(bool isFilled); 56 void SetColorStrategy(int colorStrategy); 57 58 const Color& GetColor() const; 59 float GetOffsetX() const; 60 float GetOffsetY() const; 61 float GetAlpha() const; 62 float GetElevation() const; 63 float GetRadius() const; 64 const std::shared_ptr<RSPath>& GetPath() const; 65 bool GetMask() const; 66 bool GetIsFilled() const; 67 int GetColorStrategy() const; 68 69 bool IsValid() const; 70 71 private: 72 Color color_ = Color::FromArgbInt(DEFAULT_SPOT_COLOR); 73 float offsetX_ = DEFAULT_SHADOW_OFFSET_X; 74 float offsetY_ = DEFAULT_SHADOW_OFFSET_Y; 75 float radius_ = DEFAULT_SHADOW_RADIUS; 76 float elevation_ = 0.f; 77 std::shared_ptr<RSPath> path_ = nullptr; 78 bool imageMask_ = false; 79 bool isFilled_ = false; 80 int colorStrategy_ = SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE; 81 }; 82 } // namespace Rosen 83 } // namespace OHOS 84 85 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_SHADOW_H 86