1 /* 2 * Copyright (c) 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 RENDER_SERVICE_BASE_PROPERTY_RS_PROPERTY_DRAWABLE_BOUNDS_GEOMETRY_H 17 #define RENDER_SERVICE_BASE_PROPERTY_RS_PROPERTY_DRAWABLE_BOUNDS_GEOMETRY_H 18 19 #include <utility> 20 21 #include "include/core/SkPaint.h" 22 23 #include "property/rs_property_drawable.h" 24 25 namespace OHOS::Rosen { 26 class RSSkiaFilter; 27 enum class FilterType; 28 29 class RSBoundsGeometryDrawable : public RSPropertyDrawable { 30 public: 31 explicit RSBoundsGeometryDrawable() = default; 32 ~RSBoundsGeometryDrawable() override = default; 33 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 34 35 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 36 }; 37 38 class RSClipBoundsDrawable : public RSPropertyDrawable { 39 public: 40 explicit RSClipBoundsDrawable() = default; 41 ~RSClipBoundsDrawable() override = default; 42 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 43 44 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 45 }; 46 47 // ============================================================================ 48 // PointLight 49 class RSPointLightDrawable : public RSPropertyDrawable { 50 public: 51 explicit RSPointLightDrawable() = default; 52 ~RSPointLightDrawable() override = default; 53 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 54 55 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 56 }; 57 58 // ============================================================================ 59 // Border 60 class RSBorderDrawable : public RSPropertyDrawable { 61 public: RSBorderDrawable(Drawing::Brush && brush,Drawing::Pen && pen)62 explicit RSBorderDrawable(Drawing::Brush&& brush, Drawing::Pen&& pen) 63 : RSPropertyDrawable(), brush_(std::move(brush)), pen_(std::move(pen)) 64 {} 65 ~RSBorderDrawable() override = default; 66 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 67 68 protected: 69 Drawing::Brush brush_; 70 Drawing::Pen pen_; 71 }; 72 73 class RSBorderDRRectDrawable : public RSBorderDrawable { 74 public: 75 explicit RSBorderDRRectDrawable(Drawing::Brush&& brush, Drawing::Pen&& pen, 76 const RSProperties& properties, const bool& drawBorder); 77 ~RSBorderDRRectDrawable() override = default; 78 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 79 void OnBoundsChange(const RSProperties& properties); 80 81 private: 82 bool drawBorder_; 83 Drawing::RoundRect inner_; 84 Drawing::RoundRect outer_; 85 }; 86 87 class RSBorderFourLineDrawable : public RSBorderDrawable { 88 public: 89 explicit RSBorderFourLineDrawable(Drawing::Brush&& brush, Drawing::Pen&& pen, 90 const RSProperties& properties, const bool& drawBorder); 91 ~RSBorderFourLineDrawable() override = default; 92 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 93 void OnBoundsChange(const RSProperties& properties); 94 95 private: 96 bool drawBorder_; 97 RectF rect_; 98 }; 99 100 class RSBorderPathDrawable : public RSBorderDrawable { 101 public: 102 explicit RSBorderPathDrawable(Drawing::Brush&& brush, Drawing::Pen&& pen, 103 const RSProperties& properties, const bool& drawBorder); 104 ~RSBorderPathDrawable() override = default; 105 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 106 void OnBoundsChange(const RSProperties& properties); 107 108 private: 109 bool drawBorder_; 110 Drawing::Path borderPath_; 111 }; 112 113 class RSBorderFourLineRoundCornerDrawable : public RSBorderDrawable { 114 public: 115 explicit RSBorderFourLineRoundCornerDrawable(Drawing::Brush&& brush, Drawing::Pen&& pen, 116 const RSProperties& properties, const bool& drawBorder); 117 ~RSBorderFourLineRoundCornerDrawable() override = default; 118 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 119 void OnBoundsChange(const RSProperties& properties); 120 121 private: 122 bool drawBorder_; 123 Drawing::RoundRect innerRrect_; 124 Drawing::RoundRect rrect_; 125 }; 126 127 // ============================================================================ 128 // Outline 129 class RSOutlineDrawable : public RSBorderDrawable { 130 public: RSOutlineDrawable(Drawing::Brush && brush,Drawing::Pen && pen)131 explicit RSOutlineDrawable(Drawing::Brush&& brush, Drawing::Pen&& pen) 132 : RSBorderDrawable(std::move(brush), std::move(pen)) 133 {} 134 ~RSOutlineDrawable() override = default; 135 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 136 }; 137 138 // ============================================================================ 139 // Mask 140 class RSMaskDrawable : public RSPropertyDrawable { 141 public: 142 explicit RSMaskDrawable(std::shared_ptr<RSMask> mask); 143 ~RSMaskDrawable() override = default; 144 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 145 146 protected: 147 std::shared_ptr<RSMask> mask_; 148 Drawing::Brush maskFilterBrush_; 149 Drawing::Brush maskBrush_; 150 }; 151 152 class RSSvgDomMaskDrawable : public RSMaskDrawable { 153 public: 154 explicit RSSvgDomMaskDrawable(std::shared_ptr<RSMask> mask); 155 ~RSSvgDomMaskDrawable() override = default; 156 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 157 }; 158 159 class RSSvgPictureMaskDrawable : public RSMaskDrawable { 160 public: 161 explicit RSSvgPictureMaskDrawable(std::shared_ptr<RSMask> mask); 162 ~RSSvgPictureMaskDrawable() override = default; 163 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 164 }; 165 166 class RSGradientMaskDrawable : public RSMaskDrawable { 167 public: 168 explicit RSGradientMaskDrawable(std::shared_ptr<RSMask> mask); 169 ~RSGradientMaskDrawable() override = default; 170 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 171 }; 172 173 class RSPathMaskDrawable : public RSMaskDrawable { 174 public: 175 explicit RSPathMaskDrawable(std::shared_ptr<RSMask> mask); 176 ~RSPathMaskDrawable() override = default; 177 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 178 }; 179 180 class RSPixelMapMaskDrawable : public RSMaskDrawable { 181 public: 182 explicit RSPixelMapMaskDrawable(std::shared_ptr<RSMask> mask); 183 ~RSPixelMapMaskDrawable() override = default; 184 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 185 }; 186 187 // ============================================================================ 188 // Shadow 189 class RSShadowBaseDrawable : public RSPropertyDrawable { 190 public: 191 explicit RSShadowBaseDrawable(const RSProperties& properties); 192 ~RSShadowBaseDrawable() override = default; 193 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 194 195 protected: 196 void ClipShadowPath(const RSRenderContent& content, RSPaintFilterCanvas& canvas, Drawing::Path& path) const; 197 float offsetX_; 198 float offsetY_; 199 const Color color_; 200 }; 201 202 class RSShadowDrawable : public RSShadowBaseDrawable { 203 public: 204 explicit RSShadowDrawable(const RSProperties& properties); 205 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 206 207 protected: 208 const float radius_; 209 }; 210 211 class RSColorfulShadowDrawable : public RSShadowBaseDrawable { 212 public: 213 explicit RSColorfulShadowDrawable(const RSProperties& properties); 214 ~RSColorfulShadowDrawable() override = default; 215 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 216 217 protected: 218 Drawing::Brush blurBrush_; 219 std::weak_ptr<RSRenderNode> node_; 220 }; 221 222 class RSHardwareAccelerationShadowDrawable : public RSShadowBaseDrawable { 223 public: 224 explicit RSHardwareAccelerationShadowDrawable(const RSProperties& properties); 225 ~RSHardwareAccelerationShadowDrawable() override = default; 226 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 227 228 protected: 229 const float shadowElevation_; 230 }; 231 232 // ============================================================================ 233 // DynamicLightUp 234 class RSDynamicLightUpDrawable : public RSPropertyDrawable { 235 public: 236 explicit RSDynamicLightUpDrawable() = default; 237 ~RSDynamicLightUpDrawable() override = default; 238 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 239 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 240 bool Update(const RSRenderContent& content) override; 241 }; 242 243 // ============================================================================ 244 // Binarization 245 class RSBinarizationDrawable : public RSPropertyDrawable { 246 public: 247 explicit RSBinarizationDrawable() = default; 248 ~RSBinarizationDrawable() override = default; 249 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 250 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 251 }; 252 253 // ============================================================================ 254 // LightUpEffect 255 class RSLightUpEffectDrawable : public RSPropertyDrawable { 256 public: 257 explicit RSLightUpEffectDrawable() = default; 258 ~RSLightUpEffectDrawable() override = default; 259 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 260 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 261 bool Update(const RSRenderContent& content) override; 262 }; 263 264 // ============================================================================ 265 // DynamicDim 266 class RSDynamicDimDrawable : public RSPropertyDrawable { 267 public: 268 explicit RSDynamicDimDrawable() = default; 269 ~RSDynamicDimDrawable() override = default; 270 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 271 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& context); 272 bool Update(const RSRenderContent& context) override; 273 }; 274 275 // ============================================================================ 276 // BackgroundFilter 277 class RSBackgroundFilterDrawable : public RSPropertyDrawable { 278 public: 279 explicit RSBackgroundFilterDrawable() = default; 280 ~RSBackgroundFilterDrawable() override = default; 281 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 282 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 283 bool Update(const RSRenderContent& content) override; 284 }; 285 286 // CompositingFilter 287 class RSCompositingFilterDrawable : public RSPropertyDrawable { 288 public: 289 explicit RSCompositingFilterDrawable() = default; 290 ~RSCompositingFilterDrawable() override = default; 291 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 292 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 293 bool Update(const RSRenderContent& content) override; 294 }; 295 296 bool IsForegroundFilterValid(const RSRenderContent& content); 297 298 class RSForegroundFilterDrawable : public RSPropertyDrawable { 299 public: 300 explicit RSForegroundFilterDrawable() = default; 301 ~RSForegroundFilterDrawable() override = default; 302 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 303 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 304 bool Update(const RSRenderContent& content) override; 305 }; 306 307 class RSForegroundFilterRestoreDrawable : public RSPropertyDrawable { 308 public: 309 explicit RSForegroundFilterRestoreDrawable() = default; 310 ~RSForegroundFilterRestoreDrawable() override = default; 311 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 312 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 313 bool Update(const RSRenderContent& content) override; 314 }; 315 316 // EffectDataGenerate 317 class RSEffectDataGenerateDrawable : public RSPropertyDrawable { 318 public: 319 explicit RSEffectDataGenerateDrawable() = default; 320 ~RSEffectDataGenerateDrawable() override = default; 321 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 322 bool Update(const RSRenderContent& content) override; 323 }; 324 325 // RSEffectDataApply 326 class RSEffectDataApplyDrawable : public RSPropertyDrawable { 327 public: 328 explicit RSEffectDataApplyDrawable() = default; 329 ~RSEffectDataApplyDrawable() override = default; 330 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 331 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 332 bool Update(const RSRenderContent& content) override; 333 }; 334 335 // ============================================================================ 336 // ForegroundColor 337 class RSForegroundColorDrawable : public RSPropertyDrawable { 338 public: RSForegroundColorDrawable(Drawing::Brush && brush)339 explicit RSForegroundColorDrawable(Drawing::Brush&& brush) : brush_(std::move(brush)) {} 340 ~RSForegroundColorDrawable() override = default; 341 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 342 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 343 bool Update(const RSRenderContent& content) override; 344 345 private: 346 Drawing::Brush brush_; 347 }; 348 349 // ============================================================================ 350 // Particle 351 class RSParticleDrawable : public RSPropertyDrawable { 352 public: 353 explicit RSParticleDrawable() = default; 354 ~RSParticleDrawable() override = default; 355 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 356 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 357 bool Update(const RSRenderContent& content) override; 358 }; 359 360 // ============================================================================ 361 // PixelStretch 362 class RSPixelStretchDrawable : public RSPropertyDrawable { 363 public: 364 explicit RSPixelStretchDrawable() = default; 365 ~RSPixelStretchDrawable() override = default; 366 367 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 368 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 369 bool Update(const RSRenderContent& content) override; 370 }; 371 372 // ============================================================================ 373 // Background 374 class RSBackgroundDrawable : public RSPropertyDrawable { 375 public: 376 explicit RSBackgroundDrawable() = default; 377 ~RSBackgroundDrawable() override = default; 378 static void setForceBgAntiAlias(bool antiAlias); 379 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 380 381 protected: 382 Drawing::Brush brush_; 383 }; 384 385 class RSBackgroundColorDrawable : public RSBackgroundDrawable { 386 public: RSBackgroundColorDrawable(Drawing::Color color)387 explicit RSBackgroundColorDrawable(Drawing::Color color) : RSBackgroundDrawable() 388 { 389 brush_.SetColor(color); 390 } 391 ~RSBackgroundColorDrawable() override = default; 392 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 393 bool Update(const RSRenderContent& content) override; 394 }; 395 396 class RSBackgroundShaderDrawable : public RSBackgroundDrawable { 397 public: RSBackgroundShaderDrawable(std::shared_ptr<Drawing::ShaderEffect> filter)398 explicit RSBackgroundShaderDrawable(std::shared_ptr<Drawing::ShaderEffect> filter) : RSBackgroundDrawable() 399 { 400 brush_.SetShaderEffect(std::move(filter)); 401 } 402 ~RSBackgroundShaderDrawable() override = default; 403 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 404 bool Update(const RSRenderContent& content) override; 405 }; 406 407 class RSBackgroundImageDrawable : public RSBackgroundDrawable { 408 public: 409 explicit RSBackgroundImageDrawable() = default; 410 ~RSBackgroundImageDrawable() override = default; 411 static RSPropertyDrawable::DrawablePtr Generate(const RSRenderContent& content); 412 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 413 bool Update(const RSRenderContent& content) override; 414 }; 415 416 // blend mode save and restore 417 std::unique_ptr<RSPropertyDrawable> BlendSaveDrawableGenerate(const RSRenderContent& context); 418 std::unique_ptr<RSPropertyDrawable> BlendRestoreDrawableGenerate(const RSRenderContent& context); 419 420 class RSBlendSaveLayerDrawable : public RSPropertyDrawable { 421 public: 422 explicit RSBlendSaveLayerDrawable(int blendMode, int blendModeApplyType, 423 std::shared_ptr<Drawing::Blender> blender = nullptr); 424 ~RSBlendSaveLayerDrawable() override = default; 425 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 426 427 private: 428 Drawing::Brush blendBrush_; 429 int blendModeApplyType_; 430 }; 431 432 class RSBlendFastDrawable : public RSPropertyDrawable { 433 public: 434 explicit RSBlendFastDrawable(int blendMode, std::shared_ptr<Drawing::Blender> blender = nullptr) blendMode_(blendMode)435 : blendMode_(blendMode), blender_(blender) {} 436 ~RSBlendFastDrawable() override = default; 437 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 438 439 private: 440 int blendMode_; 441 std::shared_ptr<Drawing::Blender> blender_ = nullptr; 442 }; 443 444 class RSBlendSaveLayerRestoreDrawable : public RSPropertyDrawable { 445 public: 446 explicit RSBlendSaveLayerRestoreDrawable() = default; 447 ~RSBlendSaveLayerRestoreDrawable() override = default; 448 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 449 }; 450 451 class RSBlendFastRestoreDrawable : public RSPropertyDrawable { 452 public: 453 explicit RSBlendFastRestoreDrawable() = default; 454 ~RSBlendFastRestoreDrawable() override = default; 455 void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const override; 456 }; 457 } // namespace OHOS::Rosen 458 #endif // RENDER_SERVICE_BASE_PROPERTY_RS_PROPERTY_DRAWABLE_BOUNDS_GEOMETRY_H 459