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 CUSTOM_CLIP_TO_FRAME, 66 CONTENT_STYLE, 67 CHILDREN, 68 FOREGROUND_STYLE, 69 RESTORE_FRAME, 70 71 // FG properties in Bounds clip 72 FG_SAVE_BOUNDS, 73 FG_CLIP_TO_BOUNDS, 74 BINARIZATION, 75 COLOR_FILTER, 76 DYNAMIC_DIM, 77 LIGHT_UP_EFFECT, 78 COMPOSITING_FILTER, 79 FOREGROUND_COLOR, 80 FG_RESTORE_BOUNDS, 81 82 // No clip (unless ClipToBounds is set) 83 POINT_LIGHT, 84 BORDER, 85 OVERLAY, 86 PARTICLE_EFFECT, 87 PIXEL_STRETCH, 88 89 RESTORE_BLEND_MODE, 90 RESTORE_FOREGROUND_FILTER, 91 RESTORE_ALL, 92 93 // Annotations: Please remember to update this when new slots are added. 94 // NOTE: MAX and *_END enums are using the one-past-the-end style. 95 BG_PROPERTIES_BEGIN = BACKGROUND_COLOR, 96 BG_PROPERTIES_END = ENV_FOREGROUND_COLOR_STRATEGY + 1, 97 CONTENT_PROPERTIES_BEGIN = FRAME_OFFSET, 98 CONTENT_PROPERTIES_END = FOREGROUND_STYLE + 1, 99 FG_PROPERTIES_BEGIN = BINARIZATION, 100 FG_PROPERTIES_END = FOREGROUND_COLOR + 1, 101 MAX = RESTORE_ALL + 1, 102 }; 103 104 // Pure virtual base class 105 class RSPropertyDrawable { 106 public: 107 RSPropertyDrawable() = default; 108 virtual ~RSPropertyDrawable() = default; 109 110 // not copyable and moveable 111 RSPropertyDrawable(const RSPropertyDrawable&) = delete; 112 RSPropertyDrawable(const RSPropertyDrawable&&) = delete; 113 RSPropertyDrawable& operator=(const RSPropertyDrawable&) = delete; 114 RSPropertyDrawable& operator=(const RSPropertyDrawable&&) = delete; 115 116 virtual void Draw(const RSRenderContent& content, RSPaintFilterCanvas& canvas) const = 0; 117 // return true if this drawable can be updated, default is false Update(const RSRenderContent & content)118 virtual bool Update(const RSRenderContent& content) { return false; }; 119 120 // Aliases 121 using DrawablePtr = std::unique_ptr<RSPropertyDrawable>; 122 using DrawableVec = std::array<DrawablePtr, static_cast<size_t>(RSPropertyDrawableSlot::MAX)>; 123 using DrawableGenerator = std::function<DrawablePtr(const RSRenderContent&)>; 124 125 // Generator Utilities 126 static void InitializeSaveRestore(const RSRenderContent& content, DrawableVec& drawableVec); 127 static std::unordered_set<RSPropertyDrawableSlot> GenerateDirtySlots( 128 const RSProperties& properties, const ModifierDirtyTypes& dirtyTypes); 129 static bool UpdateDrawableVec(const RSRenderContent& content, DrawableVec& drawableVec, 130 std::unordered_set<RSPropertyDrawableSlot>& dirtySlots); 131 static void UpdateSaveRestore( 132 RSRenderContent& content, DrawableVec& drawableVec, uint8_t& drawableVecStatus); 133 }; 134 } // namespace OHOS::Rosen 135 #endif // RENDER_SERVICE_BASE_PROPERTY_RS_PROPERTY_DRAWABLE_H 136