From 44d3ad2ddcf5c990c4ca8954b10fe14954380bc0 Mon Sep 17 00:00:00 2001 From: zenoslin Date: Wed, 16 Feb 2022 10:59:57 +0800 Subject: [PATCH 1/3] Fix video decoder on Web env. --- src/platform/web/DecodingPolicy.cpp | 28 ++++++++++++++++ src/rendering/caches/RenderCache.cpp | 13 +++----- .../renderers/CompositionRenderer.cpp | 9 +++-- src/video/DecodingPolicy.cpp | 33 +++++++++++++++++++ src/video/DecodingPolicy.h | 7 ++++ src/video/VideoDecoder.cpp | 8 ----- src/video/VideoDecoder.h | 7 ---- 7 files changed, 77 insertions(+), 28 deletions(-) create mode 100644 src/platform/web/DecodingPolicy.cpp create mode 100644 src/video/DecodingPolicy.cpp diff --git a/src/platform/web/DecodingPolicy.cpp b/src/platform/web/DecodingPolicy.cpp new file mode 100644 index 0000000000..ffc0726e19 --- /dev/null +++ b/src/platform/web/DecodingPolicy.cpp @@ -0,0 +1,28 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include "pag/pag.h" + +namespace pag { +void PAGVideoDecoder::SetSoftwareToHardwareEnabled(bool) { +} + +bool SoftwareToHardwareEnabled() { + return false; +} +} // namespace pag diff --git a/src/rendering/caches/RenderCache.cpp b/src/rendering/caches/RenderCache.cpp index 00b8e1b036..9d393ad3dc 100644 --- a/src/rendering/caches/RenderCache.cpp +++ b/src/rendering/caches/RenderCache.cpp @@ -25,7 +25,6 @@ #include "rendering/caches/ImageContentCache.h" #include "rendering/caches/LayerCache.h" #include "rendering/renderers/FilterRenderer.h" -#include "video/VideoDecoder.h" namespace pag { // 300M设置的大一些用于兜底,通常在大于20M时就开始随时清理。 @@ -167,10 +166,9 @@ void RenderCache::prepareFrame() { for (auto& item : layerDistances) { for (auto pagLayer : item.second) { if (pagLayer->layerType() == LayerType::PreCompose) { - auto policy = - VideoDecoder::SoftwareToHardwareEnabled() && item.first < MIN_HARDWARE_PREPARE_TIME - ? DecodingPolicy::SoftwareToHardware - : DecodingPolicy::Hardware; + auto policy = SoftwareToHardwareEnabled() && item.first < MIN_HARDWARE_PREPARE_TIME + ? DecodingPolicy::SoftwareToHardware + : DecodingPolicy::Hardware; preparePreComposeLayer(static_cast(pagLayer->layer), policy); } else if (pagLayer->layerType() == LayerType::Image) { prepareImageLayer(static_cast(pagLayer)); @@ -423,9 +421,8 @@ std::shared_ptr RenderCache::getSequenceReader(Sequence* sequenc if (reader == nullptr) { auto file = stage->getSequenceFile(sequence); reader = MakeSequenceReader(file, sequence, - VideoDecoder::SoftwareToHardwareEnabled() - ? DecodingPolicy::SoftwareToHardware - : DecodingPolicy::Hardware); + SoftwareToHardwareEnabled() ? DecodingPolicy::SoftwareToHardware + : DecodingPolicy::Hardware); if (reader && !staticComposition) { // 完全静态的序列帧不用缓存。 sequenceCaches[compositionID] = reader; diff --git a/src/rendering/renderers/CompositionRenderer.cpp b/src/rendering/renderers/CompositionRenderer.cpp index a712e90530..46f11329c3 100644 --- a/src/rendering/renderers/CompositionRenderer.cpp +++ b/src/rendering/renderers/CompositionRenderer.cpp @@ -23,7 +23,6 @@ #include "rendering/graphics/Picture.h" #include "rendering/graphics/Recorder.h" #include "rendering/readers/BitmapSequenceReader.h" -#include "video/VideoDecoder.h" namespace pag { class SequenceProxy : public TextureProxy { @@ -37,10 +36,10 @@ class SequenceProxy : public TextureProxy { } void prepare(RenderCache* cache) const override { - static_cast(cache)->prepareSequenceReader( - sequence, frame, - VideoDecoder::SoftwareToHardwareEnabled() ? DecodingPolicy::SoftwareToHardware - : DecodingPolicy::Hardware); + static_cast(cache)->prepareSequenceReader(sequence, frame, + SoftwareToHardwareEnabled() + ? DecodingPolicy::SoftwareToHardware + : DecodingPolicy::Hardware); } std::shared_ptr getTexture(RenderCache* cache) const override { diff --git a/src/video/DecodingPolicy.cpp b/src/video/DecodingPolicy.cpp new file mode 100644 index 0000000000..4f3b8f6011 --- /dev/null +++ b/src/video/DecodingPolicy.cpp @@ -0,0 +1,33 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making libpag available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file +// except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// + +#include "DecodingPolicy.h" +#include +#include "pag/pag.h" + +namespace pag { +static std::atomic_bool softwareToHardwareEnabled = true; + +void PAGVideoDecoder::SetSoftwareToHardwareEnabled(bool value) { + softwareToHardwareEnabled = value; +} + +bool SoftwareToHardwareEnabled() { + return softwareToHardwareEnabled; +} +} // namespace pag diff --git a/src/video/DecodingPolicy.h b/src/video/DecodingPolicy.h index 034ecad7ba..dbf26065c0 100644 --- a/src/video/DecodingPolicy.h +++ b/src/video/DecodingPolicy.h @@ -34,4 +34,11 @@ enum class DecodingPolicy { */ SoftwareToHardware }; + +/** + * If true, VideoDecoder uses a software decoder first, but initializes a hardware on + * async thread, and then switches to the hardware decoder when it is initialized. + * The default value is true, which will improve the performance of first frame rendering. + */ +bool SoftwareToHardwareEnabled(); } // namespace pag diff --git a/src/video/VideoDecoder.cpp b/src/video/VideoDecoder.cpp index 35928096b9..b32c517864 100644 --- a/src/video/VideoDecoder.cpp +++ b/src/video/VideoDecoder.cpp @@ -34,10 +34,6 @@ void PAGVideoDecoder::SetMaxHardwareDecoderCount(int count) { maxHardwareDecoderCount = count; } -void PAGVideoDecoder::SetSoftwareToHardwareEnabled(bool value) { - softwareToHardwareEnabled = value; -} - void PAGVideoDecoder::RegisterSoftwareDecoderFactory(SoftwareDecoderFactory* decoderFactory) { softwareDecoderFactory = decoderFactory; } @@ -46,10 +42,6 @@ bool VideoDecoder::HasHardwareDecoder() { return Platform::Current()->hasHardwareDecoder(); } -bool VideoDecoder::SoftwareToHardwareEnabled() { - return softwareToHardwareEnabled; -} - int VideoDecoder::GetMaxHardwareDecoderCount() { return maxHardwareDecoderCount; } diff --git a/src/video/VideoDecoder.h b/src/video/VideoDecoder.h index 045f605c50..2909efaf32 100644 --- a/src/video/VideoDecoder.h +++ b/src/video/VideoDecoder.h @@ -71,13 +71,6 @@ class VideoDecoder { */ static int GetMaxHardwareDecoderCount(); - /** - * If true, VideoDecoder uses a software decoder first, but initializes a hardware on - * async thread, and then switches to the hardware decoder when it is initialized. - * The default value is true, which will improve the performance of first frame rendering. - */ - static bool SoftwareToHardwareEnabled(); - /** * Creates a new video decoder by specified type. Returns a hardware video decoder if useHardware * is true, otherwise, returns a software video decoder. From bede8be28466e3691754e1036f29c3c4f2d807c4 Mon Sep 17 00:00:00 2001 From: zenoslin Date: Wed, 16 Feb 2022 12:04:33 +0800 Subject: [PATCH 2/3] Remove unused variable. --- src/video/VideoDecoder.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/video/VideoDecoder.cpp b/src/video/VideoDecoder.cpp index b32c517864..42a6bab390 100644 --- a/src/video/VideoDecoder.cpp +++ b/src/video/VideoDecoder.cpp @@ -26,7 +26,6 @@ namespace pag { static std::atomic softwareDecoderFactory = {nullptr}; -static std::atomic_bool softwareToHardwareEnabled = true; static std::atomic_int maxHardwareDecoderCount = {65535}; static std::atomic_int globalGPUDecoderCount = {0}; From 7de5cfb06035cdc8498c643c7d184e3769e50a36 Mon Sep 17 00:00:00 2001 From: zenoslin Date: Wed, 16 Feb 2022 19:24:35 +0800 Subject: [PATCH 3/3] Fix some tgfx bindings on Web env. --- web/src/pag_wasm_bindings.cpp | 46 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/web/src/pag_wasm_bindings.cpp b/web/src/pag_wasm_bindings.cpp index fde1ee5de1..b84b3f158f 100644 --- a/web/src/pag_wasm_bindings.cpp +++ b/web/src/pag_wasm_bindings.cpp @@ -192,13 +192,13 @@ EMSCRIPTEN_BINDINGS(pag) { .property("rowBytes", &tgfx::ImageInfo::rowBytes) .property("colorType", &tgfx::ImageInfo::colorType); - class_("Matrix") - .property("a", &Matrix::getScaleX) - .property("b", &Matrix::getSkewY) - .property("c", &Matrix::getSkewX) - .property("d", &Matrix::getScaleY) - .property("tx", &Matrix::getTranslateX) - .property("ty", &Matrix::getTranslateY); + class_("Matrix") + .property("a", &tgfx::Matrix::getScaleX) + .property("b", &tgfx::Matrix::getSkewY) + .property("c", &tgfx::Matrix::getSkewX) + .property("d", &tgfx::Matrix::getScaleY) + .property("tx", &tgfx::Matrix::getTranslateX) + .property("ty", &tgfx::Matrix::getTranslateY); class_("TextDocument") .smart_ptr>("TextDocument") @@ -238,18 +238,18 @@ EMSCRIPTEN_BINDINGS(pag) { .field("xHeight", &tgfx::FontMetrics::xHeight) .field("capHeight", &tgfx::FontMetrics::capHeight); - value_object("Rect") - .field("left", &Rect::left) - .field("top", &Rect::top) - .field("right", &Rect::right) - .field("bottom", &Rect::bottom); + value_object("Rect") + .field("left", &tgfx::Rect::left) + .field("top", &tgfx::Rect::top) + .field("right", &tgfx::Rect::right) + .field("bottom", &tgfx::Rect::bottom); - value_object("Point").field("x", &Point::x).field("y", &Point::y); + value_object("Point").field("x", &tgfx::Point::x).field("y", &tgfx::Point::y); - value_object("Color") - .field("red", &Color::red) - .field("green", &Color::green) - .field("blue", &Color::blue); + value_object("Color") + .field("red", &tgfx::Color::red) + .field("green", &tgfx::Color::green) + .field("blue", &tgfx::Color::blue); value_object("Marker") .field("startTime", &Marker::startTime) @@ -262,11 +262,11 @@ EMSCRIPTEN_BINDINGS(pag) { .value("INVERSE_WINDING", tgfx::PathFillType::InverseWinding) .value("INVERSE_EVEN_ODD", tgfx::PathFillType::InverseEvenOdd); - enum_("ColorType") - .value("Unknown", ColorType::Unknown) - .value("ALPHA_8", ColorType::ALPHA_8) - .value("RGBA_8888", ColorType::RGBA_8888) - .value("BGRA_8888", ColorType::BGRA_8888); + enum_("ColorType") + .value("Unknown", tgfx::ColorType::Unknown) + .value("ALPHA_8", tgfx::ColorType::ALPHA_8) + .value("RGBA_8888", tgfx::ColorType::RGBA_8888) + .value("BGRA_8888", tgfx::ColorType::BGRA_8888); enum_("LayerType") .value("Unknown", LayerType::Unknown) @@ -289,7 +289,7 @@ EMSCRIPTEN_BINDINGS(pag) { register_vector>("VectorPAGLayer"); register_vector("VectorString"); - register_vector("VectorPoint"); + register_vector("VectorPoint"); register_vector("VectorMarker"); function("_SetFallbackFontNames", optional_override([](std::vector fontNames) {