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_BASE_RENDER_RENDER_RS_SHADOW_H 17 #define RENDER_SERVICE_BASE_RENDER_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 = 0xFF000000; 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 enum SHADOW_MASK_STRATEGY : int { 44 MASK_NONE = 0, // not use the mask strategy 45 MASK_BLUR = 1, // use original image to blur 46 MASK_COLOR_BLUR = 2, // use BlenMode SRC_IN set color on image, then to blur 47 }; 48 49 class RSShadow { 50 public: 51 RSShadow(); 52 virtual ~RSShadow(); 53 void SetColor(Color color); 54 void SetOffsetX(float offsetX); 55 void SetOffsetY(float offsetY); 56 void SetAlpha(float alpha); 57 void SetElevation(float elevation); 58 void SetRadius(float radius); 59 void SetPath(const std::shared_ptr<RSPath>& path); 60 void SetMask(int imageMask); 61 void SetIsFilled(bool isFilled); 62 void SetColorStrategy(int colorStrategy); 63 64 const Color& GetColor() const; 65 float GetOffsetX() const; 66 float GetOffsetY() const; 67 float GetAlpha() const; 68 float GetElevation() const; 69 float GetRadius() const; 70 const std::shared_ptr<RSPath>& GetPath() const; 71 int GetMask() const; 72 bool GetIsFilled() const; 73 int GetColorStrategy() const; 74 75 bool IsValid() const; 76 77 private: 78 Color color_ = Color::FromArgbInt(DEFAULT_SPOT_COLOR); 79 float offsetX_ = DEFAULT_SHADOW_OFFSET_X; 80 float offsetY_ = DEFAULT_SHADOW_OFFSET_Y; 81 float radius_ = DEFAULT_SHADOW_RADIUS; 82 float elevation_ = 0.f; 83 std::shared_ptr<RSPath> path_ = nullptr; 84 int imageMask_ = SHADOW_MASK_STRATEGY::MASK_NONE; 85 bool isFilled_ = false; 86 int colorStrategy_ = SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE; 87 }; 88 } // namespace Rosen 89 } // namespace OHOS 90 91 #endif // RENDER_SERVICE_BASE_RENDER_RENDER_RS_SHADOW_H 92