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_H 17 #define RENDER_SERVICE_BASE_PROPERTY_RS_PROPERTY_DRAWABLE_H 18 19 #include <bitset> 20 #include <memory> 21 #include <set> 22 #include <vector> 23 24 #include "modifier/rs_render_modifier.h" 25 26 namespace OHOS::Rosen { 27 class RSPaintFilterCanvas; 28 class RSProperties; 29 class RSRenderContent; 30 class RSRenderNode; 31 32 // NOTE: MUST update DrawableGeneratorLut in rs_property_drawable.cpp when new slots are added 33 enum class RSPropertyDrawableSlot : uint8_t { 34 INVALID = 0, 35 SAVE_ALL, 36 37 // Bounds Geometry 38 BOUNDS_MATRIX, 39 ALPHA, 40 MASK, 41 TRANSITION, 42 ENV_FOREGROUND_COLOR, 43 SHADOW, 44 FOREGROUND_FILTER, 45 OUTLINE, 46 47 // BG properties in Bounds Clip 48 BG_SAVE_BOUNDS, 49 CLIP_TO_BOUNDS, 50 BLEND_MODE, 51 BACKGROUND_COLOR, 52 BACKGROUND_SHADER, 53 BACKGROUND_IMAGE, 54 BACKGROUND_FILTER, 55 USE_EFFECT, 56 BACKGROUND_STYLE, 57 DYNAMIC_LIGHT_UP, 58 ENV_FOREGROUND_COLOR_STRATEGY, 59 BG_RESTORE_BOUNDS, 60 61 // Frame Geometry 62 SAVE_FRAME, 63 FRAME_OFFSET, 64 CLIP_TO_FRAME, 65 CONTENT_STYLE, 66 CHILDREN, 67 FOREGROUND_STYLE, 68 RESTORE_FRAME, 69 70 // FG properties in Bounds clip 71 FG_SAVE_BOUNDS, 72 FG_CLIP_TO_BOUNDS, 73 BINARIZATION, 74 COLOR_FILTER, 75 DYNAMIC_DIM, 76 LIGHT_UP_EFFECT, 77 COMPOSITING_FILTER, 78 FOREGROUND_COLOR, 79 FG_RESTORE_BOUNDS, 80 81 // No clip (unless ClipToBounds is set) 82 POINT_LIGHT, 83 BORDER, 84 OVERLAY, 85 PARTICLE_EFFECT, 86 PIXEL_STRETCH, 87 88 RESTORE_BLEND_MODE, 89 RESTORE_FOREGROUND_FILTER, 90 RESTORE_ALL, 91 92 // Annotations: Please remember to update this when new slots are added. 93 // NOTE: MAX and *_END enums are using the one-past-the-end style. 94 BG_PROPERTIES_BEGIN = BACKGROUND_COLOR, 95 BG_PROPERTIES_END = ENV_FOREGROUND_COLOR_STRATEGY + 1, 96 CONTENT_PROPERTIES_BEGIN = FRAME_OFFSET, 97 CONTENT_PROPERTIES_END = FOREGROUND_STYLE + 1, 98 FG_PROPERTIES_BEGIN = BINARIZATION, 99 FG_PROPERTIES_END = FOREGROUND_COLOR + 1, 100 MAX = RESTORE_ALL + 1, 101 }; 102 103 // Pure virtual base class 104 class RSPropertyDrawable { 105 public: 106 RSPropertyDrawable() = default; 107 virtual ~RSPropertyDrawable() = default; 108 109 // not copyable and moveable 110 RSPropertyDrawable(const RSPropertyDrawable&) = delete; 111 RSPropertyDrawable(const RSPropertyDrawable&&) = delete; 112 RSPropertyDrawable& operator=(const RSPropertyDrawable&) = delete; 113 RSPropertyDrawable& operator=(const RSPropertyDrawable&&) = delete; 114 115 virtual void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const = 0; 116 // return true if this drawable can be updated, default is false Update(const RSRenderContent & content)117 virtual bool Update(const RSRenderContent& content) { return false; }; 118 119 // Aliases 120 using DrawablePtr = std::unique_ptr<RSPropertyDrawable>; 121 using DrawableVec = std::array<DrawablePtr, static_cast<size_t>(RSPropertyDrawableSlot::MAX)>; 122 using DrawableGenerator = std::function<DrawablePtr(const RSRenderContent&)>; 123 124 // Generator Utilities 125 static void InitializeSaveRestore(const RSRenderContent& content, DrawableVec& drawableVec); 126 static std::unordered_set<RSPropertyDrawableSlot> GenerateDirtySlots( 127 const RSProperties& properties, const ModifierDirtyTypes& dirtyTypes); 128 static bool UpdateDrawableVec(const RSRenderContent& content, DrawableVec& drawableVec, 129 std::unordered_set<RSPropertyDrawableSlot>& dirtySlots); 130 static void UpdateSaveRestore( 131 RSRenderContent& content, DrawableVec& drawableVec, uint8_t& drawableVecStatus); 132 }; 133 } // namespace OHOS::Rosen 134 #endif // RENDER_SERVICE_BASE_PROPERTY_RS_PROPERTY_DRAWABLE_H 135