diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-06-11 17:11:13 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-06-11 17:11:13 +0200 |
commit | c96fdcb4d639ae52ad1d2c812a07e5667849fe71 (patch) | |
tree | 37ace7d7fbb79a211d604a9e7a3204e454ee8720 | |
parent | 26b593b1eac483f700c72b4195e372f4b92acc7f (diff) |
Optimize shaders, only update youtube decryption function once every 5 minutes, smoother movement with smaller card items
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | include/Body.hpp | 1 | ||||
-rw-r--r-- | plugins/youtube/Signature.hpp | 2 | ||||
-rw-r--r-- | shaders/circle_mask.glsl | 4 | ||||
-rw-r--r-- | shaders/rounded_rectangle.glsl | 11 | ||||
-rw-r--r-- | shaders/rounded_rectangle_mask.glsl | 5 | ||||
-rw-r--r-- | src/Body.cpp | 3 | ||||
-rw-r--r-- | src/RoundedRectangle.cpp | 2 | ||||
-rw-r--r-- | src/plugins/youtube/Signature.cpp | 6 |
9 files changed, 21 insertions, 16 deletions
@@ -163,4 +163,5 @@ Cancel search when new search happens. Update item height when it switches from not being merged with previous to being merged with previous. This happens when loading previous messages in matrix and the message is the top one. Reload youtube video url if the video is idle for too long. The video url is only valid for a specific amount of time (the valid duration is in the json). Improve live stream startup time by downloading the video formats in parts instead of the hls manifest? -Add youtube chapters.
\ No newline at end of file +Add youtube chapters. +Faster seeking for long youtube videos.
\ No newline at end of file diff --git a/include/Body.hpp b/include/Body.hpp index 623afca..121fbb5 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -369,6 +369,7 @@ namespace QuickMedia { sf::Vector2f item_background_target_pos; sf::Vector2f item_background_prev_size; sf::Vector2f item_background_target_size; + float item_background_target_height; TargetSetState target_set = TargetSetState::NOT_SET; // TODO: Instead of using this, add functions for modifying |items| and apply the filter on those new items DirtyState items_dirty = DirtyState::FALSE; diff --git a/plugins/youtube/Signature.hpp b/plugins/youtube/Signature.hpp index 8c782f9..01299ee 100644 --- a/plugins/youtube/Signature.hpp +++ b/plugins/youtube/Signature.hpp @@ -4,7 +4,6 @@ #include <string> #include <vector> #include <map> -#include <mutex> #include <time.h> namespace QuickMedia { @@ -36,7 +35,6 @@ namespace QuickMedia { // TODO: Remove this task and instead add the network download task to a queue and add a poll function to check if it has finished downloading // or if it needs to be updated. AsyncTask<void> poll_task; - std::mutex update_signature_mutex; std::string decryption_function; time_t decrypt_function_last_updated = 0; bool running = false; diff --git a/shaders/circle_mask.glsl b/shaders/circle_mask.glsl index 198191e..61c87cb 100644 --- a/shaders/circle_mask.glsl +++ b/shaders/circle_mask.glsl @@ -13,7 +13,5 @@ void main() { float radius = 0.49 * resolution.y; vec4 texture_color = texture2D(texture, gl_TexCoord[0].xy); - vec4 layer1 = vec4(0.0, 0.0, 0.0, 0.0); - vec4 layer2 = circle(uv, center, radius, texture_color); - gl_FragColor = mix(layer1, layer2, layer2.a); + gl_FragColor = circle(uv, center, radius, texture_color); } diff --git a/shaders/rounded_rectangle.glsl b/shaders/rounded_rectangle.glsl index 88a057a..d06a4ba 100644 --- a/shaders/rounded_rectangle.glsl +++ b/shaders/rounded_rectangle.glsl @@ -12,10 +12,11 @@ void main() { vec2 uv = gl_TexCoord[0].xy * resolution; vec2 center = resolution * 0.5; vec2 size = resolution * 0.5; - vec4 background_color = vec4(0.0, 0.0, 0.0, 0.0); + float a = clamp(rounded_rect(uv - center, size - radius, radius), 0.0, 1.0); - vec4 front_color = gl_Color; - if(uv.x >= band_pos.x && uv.x <= band_pos.x + band_size.x && uv.y >= band_pos.y && uv.y <= band_pos.y + band_size.y) - front_color = band_color; - gl_FragColor = mix(front_color, background_color, a); + // same as: if(uv.x >= band_pos.x && uv.x <= band_pos.x + band_size.x && uv.y >= band_pos.y && uv.y <= band_pos.y + band_size.y) + vec2 band_blend = step(band_pos, uv) - step(band_pos + band_size, uv); + vec4 front_color = mix(gl_Color, band_color, band_blend.x*band_blend.y); + front_color.a *= (1.0 - a); + gl_FragColor = front_color; }
\ No newline at end of file diff --git a/shaders/rounded_rectangle_mask.glsl b/shaders/rounded_rectangle_mask.glsl index 4725273..f6ff1a1 100644 --- a/shaders/rounded_rectangle_mask.glsl +++ b/shaders/rounded_rectangle_mask.glsl @@ -10,8 +10,9 @@ void main() { vec2 uv = gl_TexCoord[0].xy * resolution; vec2 center = resolution * 0.5; vec2 size = resolution * 0.5; - vec4 background_color = vec4(0.0, 0.0, 0.0, 0.0); + vec4 texture_color = texture2D(texture, gl_TexCoord[0].xy); float a = clamp(rounded_rect(uv - center, size - radius, radius), 0.0, 1.0); - gl_FragColor = mix(texture_color, background_color, a); + texture_color.a *= (1.0 - a); + gl_FragColor = texture_color; }
\ No newline at end of file diff --git a/src/Body.cpp b/src/Body.cpp index df52386..3c210a8 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -708,7 +708,7 @@ namespace QuickMedia { const float speed = 30.0f; - const sf::Vector2f item_background_size_diff = item_background_target_size - item_background_prev_size; + const sf::Vector2f item_background_size_diff = sf::Vector2f(item_background_target_size.x, item_background_target_height) - item_background_prev_size; const float item_background_size_speed = instant_move ? 1000.0f : speed; const sf::Vector2f item_background_new_size = item_background_prev_size + (item_background_size_diff * std::min(1.0f, frame_time * item_background_size_speed)); item_background_prev_size = item_background_new_size; @@ -941,6 +941,7 @@ namespace QuickMedia { if(item_index == selected_item) { item_background_target_pos = pos; item_background_target_size = sf::Vector2f(item_width, item_height); + item_background_target_height = item_height; if(target_set == TargetSetState::NOT_SET) target_set = TargetSetState::SET; } diff --git a/src/RoundedRectangle.cpp b/src/RoundedRectangle.cpp index afd733f..4aad699 100644 --- a/src/RoundedRectangle.cpp +++ b/src/RoundedRectangle.cpp @@ -17,6 +17,8 @@ namespace QuickMedia { vertices[1].texCoords = sf::Vector2f(1.0f, 0.0f); vertices[2].texCoords = sf::Vector2f(1.0f, 1.0f); vertices[3].texCoords = sf::Vector2f(0.0f, 1.0f); + + set_size(size); } void RoundedRectangle::set_position(sf::Vector2f pos) { diff --git a/src/plugins/youtube/Signature.cpp b/src/plugins/youtube/Signature.cpp index 30093d5..2460f8a 100644 --- a/src/plugins/youtube/Signature.cpp +++ b/src/plugins/youtube/Signature.cpp @@ -5,6 +5,7 @@ #include "../../../include/StringUtils.hpp" #include "../../../include/Program.hpp" #include <regex> +#include <mutex> #include <unistd.h> namespace QuickMedia { @@ -14,7 +15,8 @@ namespace QuickMedia { }; static YoutubeSignatureDecryptor *instance = nullptr; - static const int timeout_default_sec = 60; + static std::mutex update_signature_mutex; + static const int timeout_default_sec = 60 * 5; // 5 minutes bool YoutubeSignatureDecryptor::js_code_to_operations(const std::string &function_body_str, const std::string &var_body_str, std::vector<DecryptFuncCall> &new_func_calls, std::map<std::string, DecryptFunction> &new_func_decls) { std::vector<std::string> function_body; @@ -170,6 +172,7 @@ namespace QuickMedia { // static YoutubeSignatureDecryptor& YoutubeSignatureDecryptor::get_instance() { + std::lock_guard<std::mutex> lock(update_signature_mutex); if(!instance) instance = new YoutubeSignatureDecryptor(); return *instance; @@ -183,7 +186,6 @@ namespace QuickMedia { int num_tries = 0; const int max_tries = 30; while(running && num_tries < max_tries && !program_is_dead_in_current_thread()) { // 6 seconds in total - std::lock_guard<std::mutex> lock(update_signature_mutex); if(up_to_date) break; ++num_tries; |