-
Notifications
You must be signed in to change notification settings - Fork 379
Working on caching box shadows #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ZilverBlade
wants to merge
13
commits into
mikke89:master
Choose a base branch
from
ZilverBlade:799-box-shadow-caching
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
eb1a0e1
initial work on caching box shadows
f39fc20
hash function for the BoxShadowGeometryInfo and passing the mesh data…
cf9e163
fixed several compiler errors, using shared pointers, added cleanup f…
0bd3d6b
replaced HashCombine with existing implementation, and fixed build er…
ZilverBlade ec8990e
fixed global quantifier errors
ZilverBlade efe47a5
Comment cleanup and fixed resource leak error
efddb5c
refactored the box shadow cache (Currently broken!) to be more simila…
ZilverBlade 646de5a
Implemented cache, added BoxShadowCache.cpp to the cmakelists.txt and…
ZilverBlade b9fb7bc
fixed some compiler errors and added missing initialisation and destr…
ZilverBlade 5abfb48
Merge branch 'mikke89:master' into 799-box-shadow-caching
ZilverBlade 9500871
fixed compile errors and fixed missing opacity and texture offset in …
ZilverBlade 8eb1d8a
Fixed missing background border geometry cache
ZilverBlade 360d109
fixed some compiler errors
ZilverBlade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,13 +30,15 @@ | |
| #define RMLUI_CORE_RENDERMANAGER_H | ||
|
|
||
| #include "CallbackTexture.h" | ||
| #include "DecorationTypes.h" | ||
| #include "Mesh.h" | ||
| #include "RenderBox.h" | ||
| #include "RenderInterface.h" | ||
| #include "StableVector.h" | ||
| #include "Types.h" | ||
| #include "Utilities.h" | ||
|
||
|
|
||
| namespace Rml { | ||
|
|
||
| class Geometry; | ||
| class CompiledFilter; | ||
| class CompiledShader; | ||
|
|
@@ -67,10 +69,10 @@ struct RenderState { | |
| }; | ||
|
|
||
| /** | ||
| A wrapper over the render interface, which tracks its state and resources. | ||
| A wrapper over the render interface, which tracks its state and resources. | ||
|
|
||
| All operations to be submitted to the render interface should go through this class. | ||
| */ | ||
| All operations to be submitted to the render interface should go through this class. | ||
| */ | ||
| class RMLUICORE_API RenderManager : NonCopyMoveable { | ||
| public: | ||
| RenderManager(RenderInterface* render_interface); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| /* | ||
| * This source file is part of RmlUi, the HTML/CSS Interface Middleware | ||
| * | ||
| * For the latest information, see http://github.com/mikke89/RmlUi | ||
| * | ||
| * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd | ||
| * Copyright (c) 2019-2023 The RmlUi Team, and contributors | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| */ | ||
|
|
||
| #include "BoxShadowCache.h" | ||
| #include "../../Include/RmlUi/Core/Box.h" | ||
| #include "../../Include/RmlUi/Core/CallbackTexture.h" | ||
| #include "../../Include/RmlUi/Core/ComputedValues.h" | ||
| #include "../../Include/RmlUi/Core/Core.h" | ||
| #include "../../Include/RmlUi/Core/DecorationTypes.h" | ||
| #include "../../Include/RmlUi/Core/Element.h" | ||
| #include "../../Include/RmlUi/Core/ElementDocument.h" | ||
| #include "../../Include/RmlUi/Core/FileInterface.h" | ||
| #include "../../Include/RmlUi/Core/Geometry.h" | ||
| #include "../../Include/RmlUi/Core/Math.h" | ||
| #include "../../Include/RmlUi/Core/MeshUtilities.h" | ||
| #include "../../Include/RmlUi/Core/RenderManager.h" | ||
| #include "../../Include/RmlUi/Core/Texture.h" | ||
| #include "../../Include/RmlUi/Core/Utilities.h" | ||
| #include "../Core/ControlledLifetimeResource.h" | ||
| #include "ElementBackgroundBorder.h" | ||
| #include "GeometryBoxShadow.h" | ||
| #include <algorithm> | ||
|
|
||
| namespace Rml { | ||
|
|
||
| struct BoxShadowCacheData { | ||
| StableUnorderedMap<BoxShadowGeometryInfo, WeakPtr<BoxShadowData>> handles; | ||
| }; | ||
|
|
||
| BoxShadowData::~BoxShadowData() | ||
| { | ||
| ReleaseHandle(this); | ||
| } | ||
|
|
||
| static ControlledLifetimeResource<BoxShadowCacheData> shadow_cache_data; | ||
|
|
||
| void BoxShadowCache::Initialize() | ||
| { | ||
| shadow_cache_data.Initialize(); | ||
| } | ||
|
|
||
| void BoxShadowCache::Shutdown() | ||
| { | ||
| shadow_cache_data.Shutdown(); | ||
| } | ||
|
|
||
| static SharedPtr<BoxShadowData> GetOrCreateBoxShadow(RenderManager& render_manager, const BoxShadowGeometryInfo& info) | ||
| { | ||
| auto handles = shadow_cache_data->handles; | ||
| auto it_handle = std::find(shadow_cache_data->handles.begin(), shadow_cache_data->handles.end(), info); | ||
| if (it_handle == shadow_cache_data->handles.end()) | ||
| { | ||
| SharedPtr<BoxShadowData> result = it_handle->second.lock(); | ||
| RMLUI_ASSERTMSG(result, "Failed to lock handle in SVG cache"); | ||
| return result; | ||
| } | ||
| const auto iterator_inserted = handles.emplace(info, WeakPtr<BoxShadowData>()); | ||
| RMLUI_ASSERTMSG(iterator_inserted.second, "Could not insert entry into the SVG cache handle map, duplicate key."); | ||
| const BoxShadowGeometryInfo& inserted_key = iterator_inserted.first->first; | ||
| WeakPtr<BoxShadowData>& inserted_weak_data_pointer = iterator_inserted.first->second; | ||
|
|
||
| auto shadow_handle = MakeShared<BoxShadowData>(/*TODO*/); | ||
| inserted_weak_data_pointer = shadow_handle; | ||
| return shadow_handle; | ||
| } | ||
|
|
||
| static void ReleaseHandle(BoxShadowData* handle) | ||
| { | ||
| // There are no longer any users of the cache entry uniquely identified by the handle address. Start from the | ||
| // tip (i.e. per-color data) and remove that entry from its parent. Move up the cache ancestry and erase any | ||
| // entries that no longer have any children. | ||
| // auto& handles = shadow_cache_data->handles; | ||
| // const BoxShadowGeometryInfo& key = handle->cache_key; | ||
| // | ||
| // auto it_handle = handles.find(key); | ||
| // RMLUI_ASSERT(it_handle != handles.cend()); | ||
| // | ||
| // handles.erase(it_handle); | ||
| // | ||
| //#ifdef RMLUI_DEBUG | ||
| // size_t count_unique_entries = 0; | ||
| // /*for (auto& document : documents) | ||
| // { | ||
| // RMLUI_ASSERT(!document.second.textures.empty()); | ||
| // for (auto& size_data : document.second.textures) | ||
| // { | ||
| // RMLUI_ASSERT(!size_data.geometries.empty()); | ||
| // count_unique_entries += size_data.geometries.size(); | ||
| // } | ||
| // }*/ | ||
| // RMLUI_ASSERT(count_unique_entries == handles.size()); | ||
| //#endif | ||
| } | ||
|
|
||
| SharedPtr<BoxShadowData> BoxShadowCache::GetHandle(Element* element) | ||
| { | ||
| RenderManager* render_manager = element->GetRenderManager(); | ||
| if (!render_manager) | ||
| return {}; | ||
|
|
||
| const ComputedValues& computed = element->GetComputedValues(); | ||
| const ColourbPremultiplied colour = computed.image_color().ToPremultiplied(computed.opacity()); | ||
|
|
||
| const Property* p_box_shadow = element->GetLocalProperty(PropertyId::BoxShadow); | ||
| RMLUI_ASSERT(p_box_shadow->value.GetType() == Variant::BOXSHADOWLIST); | ||
| BoxShadowList shadow_list = p_box_shadow->value.Get<BoxShadowList>(); | ||
|
|
||
| ColourbPremultiplied background_color = computed.background_color().ToPremultiplied(); | ||
| Array<ColourbPremultiplied, 4> border_colors = { | ||
| computed.border_top_color().ToPremultiplied(), | ||
| computed.border_right_color().ToPremultiplied(), | ||
| computed.border_bottom_color().ToPremultiplied(), | ||
| computed.border_left_color().ToPremultiplied(), | ||
| }; | ||
| const CornerSizes border_radius = computed.border_radius(); | ||
| BoxShadowGeometryInfo geom_info = GeometryBoxShadow::Resolve(element, shadow_list, border_radius, background_color, border_colors); | ||
mikke89 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return GetOrCreateBoxShadow(*render_manager, geom_info); | ||
| } | ||
| } // namespace Rml | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * This source file is part of RmlUi, the HTML/CSS Interface Middleware | ||
| * | ||
| * For the latest information, see http://github.com/mikke89/RmlUi | ||
| * | ||
| * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd | ||
| * Copyright (c) 2019-2023 The RmlUi Team, and contributors | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef RMLUI_CORE_BOXSHADOWCACHE_H | ||
| #define RMLUI_CORE_BOXSHADOWCACHE_H | ||
|
|
||
| #include "../../Include/RmlUi/Core/RenderBox.h" | ||
| #include "../../Include/RmlUi/Core/Types.h" | ||
|
|
||
| namespace Rml { | ||
| struct BoxShadowGeometryInfo; | ||
|
|
||
| struct BoxShadowData : NonCopyMoveable { | ||
| BoxShadowData(); | ||
| ~BoxShadowData(); | ||
|
|
||
| Texture texture; | ||
| Vector2f intrinsic_dimensions; | ||
| const BoxShadowGeometryInfo& cache_key; | ||
| }; | ||
|
|
||
| class BoxShadowCache { | ||
| public: | ||
| static void Initialize(); | ||
| static void Shutdown(); | ||
|
|
||
| /// Returns a handle to BoxShadow data matching the parameters - creates new data if none is found. | ||
| /// @param[in] element Element for which to calculate and cache the box shadow | ||
| /// @return A handle to the BoxShadow data, with automatic reference counting. | ||
| static SharedPtr<BoxShadowData> GetHandle(Element* element); | ||
| }; | ||
|
|
||
| } // namespace Rml | ||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.