Skip to content

Commit 94ff965

Browse files
authored
Merge branch 'Tencent:main' into build_viewer
2 parents e7c8a96 + 52f46bf commit 94ff965

File tree

13 files changed

+8170
-8129
lines changed

13 files changed

+8170
-8129
lines changed

CMakeLists.txt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden)
2121

2222
# Options for building libpag
2323
option(PAG_USE_OPENGL "Allow use of OpenGL as GPU backend" ON)
24-
option(PAG_USE_SWIFTSHADER "Allow build with SwiftShader library" OFF)
24+
option(PAG_USE_SWIFTSHADER "Allow build with the SwiftShader library" OFF)
25+
option(PAG_USE_ANGLE "Allow build with the ANGLE library" OFF)
2526
option(PAG_USE_QT "Allow build with QT frameworks" OFF)
2627
option(PAG_USE_RTTR "Enable RTTR support" OFF)
2728
option(PAG_USE_HARFBUZZ "Enable HarfBuzz support" OFF)
@@ -76,12 +77,13 @@ endif ()
7677

7778
if (PAG_USE_QT)
7879
set(PAG_USE_SWIFTSHADER OFF)
80+
set(PAG_USE_ANGLE OFF)
81+
elseif (PAG_USE_SWIFTSHADER)
82+
set(PAG_USE_ANGLE OFF)
7983
endif ()
8084

81-
if (PAG_USE_QT OR PAG_USE_SWIFTSHADER)
85+
if (PAG_USE_QT OR PAG_USE_SWIFTSHADER OR PAG_USE_ANGLE)
8286
set(PAG_USE_OPENGL ON)
83-
else ()
84-
set(USE_NATIVE_PLATFORM ON)
8587
endif ()
8688

8789
if (PAG_USE_FFAVC)
@@ -201,6 +203,8 @@ elseif (PAG_USE_SWIFTSHADER)
201203
list(APPEND PAG_INCLUDES ${TGFX_DIR}/vendor/swiftshader/include)
202204
file(GLOB_RECURSE PLATFORM_FILES src/platform/swiftshader/*.*)
203205
list(APPEND PAG_FILES ${PLATFORM_FILES})
206+
else ()
207+
set(USE_NATIVE_PLATFORM ON)
204208
endif ()
205209

206210
if (PAG_USE_RTTR)
@@ -350,9 +354,16 @@ elseif (WIN32)
350354
list(APPEND PAG_DEFINES NOMINMAX _USE_MATH_DEFINES)
351355

352356
if (USE_NATIVE_PLATFORM)
353-
list(APPEND PAG_INCLUDES ${TGFX_DIR}/vendor/angle/include)
354-
file(GLOB ANGLE_LIBS ${TGFX_DIR}/vendor/angle/${PLATFORM}/${ARCH}/*${CMAKE_STATIC_LIBRARY_SUFFIX})
355-
list(APPEND PAG_STATIC_LIBS ${ANGLE_LIBS})
357+
if (PAG_USE_ANGLE)
358+
list(APPEND PAG_DEFINES PAG_USE_ANGLE)
359+
list(APPEND PAG_INCLUDES ${TGFX_DIR}/vendor/angle/include)
360+
file(GLOB ANGLE_LIBS ${TGFX_DIR}/vendor/angle/${PLATFORM}/${ARCH}/*${CMAKE_STATIC_LIBRARY_SUFFIX})
361+
list(APPEND PAG_STATIC_LIBS ${ANGLE_LIBS})
362+
else ()
363+
find_library(OPENGL_LIB opengl32)
364+
list(APPEND PAG_STATIC_LIBS ${OPENGL_LIB})
365+
endif ()
366+
356367
file(GLOB_RECURSE PLATFORM_FILES src/platform/win/*.*)
357368
list(APPEND PAG_FILES ${PLATFORM_FILES})
358369
endif ()
@@ -431,6 +442,7 @@ if (NOT HAS_CUSTOM_TGFX_DIR AND EXISTS ${TGFX_CACHE_DIR})
431442
list(APPEND TGFX_OPTIONS "-DTGFX_USE_OPENGL=${PAG_USE_OPENGL}")
432443
list(APPEND TGFX_OPTIONS "-DTGFX_USE_QT=${PAG_USE_QT}")
433444
list(APPEND TGFX_OPTIONS "-DTGFX_USE_SWIFTSHADER=${PAG_USE_SWIFTSHADER}")
445+
list(APPEND TGFX_OPTIONS "-DTGFX_USE_ANGLE=${PAG_USE_ANGLE}")
434446
list(APPEND TGFX_OPTIONS "-DTGFX_USE_FREETYPE=${PAG_USE_FREETYPE}")
435447
list(APPEND TGFX_OPTIONS "-DTGFX_USE_PNG_DECODE=${PAG_USE_PNG_DECODE}")
436448
list(APPEND TGFX_OPTIONS "-DTGFX_USE_PNG_ENCODE=${PAG_USE_PNG_ENCODE}")
@@ -462,6 +474,7 @@ else ()
462474
set(TGFX_USE_OPENGL ${PAG_USE_OPENGL})
463475
set(TGFX_USE_QT ${PAG_USE_QT})
464476
set(TGFX_USE_SWIFTSHADER ${PAG_USE_SWIFTSHADER})
477+
set(TGFX_USE_ANGLE ${PAG_USE_ANGLE})
465478
set(TGFX_USE_FREETYPE ${PAG_USE_FREETYPE})
466479
set(TGFX_USE_PNG_DECODE ${PAG_USE_PNG_DECODE})
467480
set(TGFX_USE_PNG_ENCODE ${PAG_USE_PNG_ENCODE})

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
{
1414
"url": "${PAG_GROUP}/tgfx.git",
15-
"commit": "235ce5e99ddb33cb8679702ea6b17a7098e10023",
15+
"commit": "2d4b07c7388b5a5825fbbc032a30bb7a05e6452b",
1616
"dir": "third_party/tgfx"
1717
},
1818
{

src/platform/ohos/NativeDisplayLink.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
/////////////////////////////////////////////////////////////////////////////////////////////////
1818

1919
#pragma once
20+
21+
// clang-format off
22+
#include <stdint.h>
2023
#include <native_vsync/native_vsync.h>
24+
// clang-format on
2125
#include <functional>
2226
#include <mutex>
2327
#include "rendering/utils/DisplayLink.h"

src/platform/ohos/OHOSVideoDecoder.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ OHOSVideoDecoder::~OHOSVideoDecoder() {
100100
}
101101
}
102102
if (videoCodec != nullptr) {
103+
releaseOutputBuffer();
103104
OH_VideoDecoder_Flush(videoCodec);
104105
OH_VideoDecoder_Stop(videoCodec);
105106
OH_VideoDecoder_Destroy(videoCodec);
@@ -133,7 +134,6 @@ bool OHOSVideoDecoder::initDecoder(const OH_AVCodecCategory avCodecCategory) {
133134
OH_AVFormat* ohFormat = OH_AVFormat_Create();
134135
OH_AVFormat_SetIntValue(ohFormat, OH_MD_KEY_WIDTH, videoFormat.width);
135136
OH_AVFormat_SetIntValue(ohFormat, OH_MD_KEY_HEIGHT, videoFormat.height);
136-
OH_AVFormat_SetIntValue(ohFormat, OH_MD_KEY_VIDEO_ENABLE_LOW_LATENCY, 1);
137137
OH_AVFormat_SetIntValue(ohFormat, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
138138
ret = OH_VideoDecoder_Configure(videoCodec, ohFormat);
139139
OH_AVFormat_Destroy(ohFormat);
@@ -194,14 +194,15 @@ DecodingResult OHOSVideoDecoder::onEndOfStream() {
194194
}
195195

196196
DecodingResult OHOSVideoDecoder::onDecodeFrame() {
197+
releaseOutputBuffer();
197198
std::unique_lock<std::mutex> lock(codecUserData->outputMutex);
198199
codecUserData->outputCondition.wait(lock, [this]() {
199-
// In the PAG file, video sequence frame software decoding testing requires sending additional
200-
// data before obtaining the decoded data. If compatibility with user video decoding is desired,
201-
// retesting is necessary.
202-
return codecUserData->outputBufferInfoQueue.size() > 0 ||
203-
pendingFrames.size() <= static_cast<size_t>(videoFormat.maxReorderSize) +
204-
(codecCategory == SOFTWARE ? 1 : 0);
200+
/**
201+
* According to HarmonyOS recommendations, temporarily modify the maximum frame delivery count to 16 to avoid
202+
* freezing issues caused by the lack of decoded data on certain HarmonyOS devices. However, this change will
203+
* result in increased memory usage. Once HarmonyOS are improved, appropriate adjustments will be made here.
204+
*/
205+
return codecUserData->outputBufferInfoQueue.size() > 0 || pendingFrames.size() <= 16;
205206
});
206207
if (codecUserData->outputBufferInfoQueue.size() > 0) {
207208
codecBufferInfo = codecUserData->outputBufferInfoQueue.front();
@@ -215,11 +216,6 @@ DecodingResult OHOSVideoDecoder::onDecodeFrame() {
215216
lock.unlock();
216217
return DecodingResult::Success;
217218
}
218-
int ret = OH_VideoDecoder_FreeOutputBuffer(videoCodec, codecBufferInfo.bufferIndex);
219-
if (ret != AV_ERR_OK) {
220-
LOGE("OH_VideoDecoder_FreeOutputBuffer failed, ret:%d", ret);
221-
return DecodingResult::Error;
222-
}
223219
if (codecBufferInfo.attr.flags == AVCODEC_BUFFER_FLAGS_EOS) {
224220
return DecodingResult::EndOfStream;
225221
}
@@ -310,4 +306,14 @@ std::shared_ptr<tgfx::ImageBuffer> OHOSVideoDecoder::onRenderFrame() {
310306
return imageBuffer;
311307
}
312308

309+
void OHOSVideoDecoder::releaseOutputBuffer() {
310+
if (codecBufferInfo.buffer) {
311+
int ret = OH_VideoDecoder_FreeOutputBuffer(videoCodec, codecBufferInfo.bufferIndex);
312+
if (ret != AV_ERR_OK) {
313+
LOGE("OH_VideoDecoder_FreeOutputBuffer failed, ret:%d", ret);
314+
}
315+
codecBufferInfo = {0, nullptr};
316+
}
317+
}
318+
313319
} // namespace pag

src/platform/ohos/OHOSVideoDecoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,6 @@ class OHOSVideoDecoder : public VideoDecoder {
101101
explicit OHOSVideoDecoder(const VideoFormat& format, bool hardware);
102102
bool initDecoder(const OH_AVCodecCategory avCodecCategory);
103103
bool start();
104+
void releaseOutputBuffer();
104105
};
105106
} // namespace pag

src/platform/win/GPUDrawable.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
#include "GPUDrawable.h"
2020
#include <windows.h>
2121
#include "base/utils/Log.h"
22+
#ifdef PAG_USE_ANGLE
2223
#include "tgfx/gpu/opengl/egl/EGLWindow.h"
24+
#else
25+
#include "tgfx/gpu/opengl/wgl/WGLWindow.h"
26+
#endif
2327

2428
namespace pag {
2529
std::shared_ptr<GPUDrawable> GPUDrawable::FromWindow(void* nativeWindow, void* sharedContext) {
@@ -56,8 +60,13 @@ std::shared_ptr<tgfx::Device> GPUDrawable::getDevice() {
5660
return nullptr;
5761
}
5862
if (window == nullptr) {
63+
#ifdef PAG_USE_ANGLE
5964
window = tgfx::EGLWindow::MakeFrom(reinterpret_cast<EGLNativeWindowType>(nativeWindow),
6065
sharedContext);
66+
#else
67+
window = tgfx::WGLWindow::MakeFrom(reinterpret_cast<HWND>(nativeWindow),
68+
reinterpret_cast<HGLRC>(sharedContext));
69+
#endif
6170
}
6271
return window ? window->getDevice() : nullptr;
6372
}
@@ -75,4 +84,4 @@ void GPUDrawable::onFreeSurface() {
7584
void GPUDrawable::present(tgfx::Context* context) {
7685
window->present(context);
7786
}
78-
} // namespace pag
87+
} // namespace pag

src/platform/win/GPUDrawable.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323
namespace tgfx {
2424
class EGLWindow;
25-
}
25+
class WGLWindow;
26+
} // namespace tgfx
2627

2728
namespace pag {
2829
class GPUDrawable : public Drawable {
@@ -51,10 +52,14 @@ class GPUDrawable : public Drawable {
5152
private:
5253
int _width = 0;
5354
int _height = 0;
55+
#ifdef PAG_USE_ANGLE
5456
std::shared_ptr<tgfx::EGLWindow> window = nullptr;
57+
#else
58+
std::shared_ptr<tgfx::WGLWindow> window = nullptr;
59+
#endif
5560
void* nativeWindow = nullptr;
5661
void* sharedContext = nullptr;
5762

5863
GPUDrawable(void* nativeWindow, void* sharedContext);
5964
};
60-
} // namespace pag
65+
} // namespace pag

src/rendering/PAGAnimator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ std::vector<int> PAGAnimator::doAdvance() {
275275

276276
void PAGAnimator::doUpdate(bool setStartTime) {
277277
locker.lock();
278-
if (task != nullptr && task->executing()) {
278+
if (task != nullptr && task->status() == tgfx::TaskStatus::Executing) {
279279
locker.unlock();
280280
return;
281281
}

src/rendering/graphics/Canvas.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ class Canvas {
105105
canvas->clear();
106106
}
107107

108-
void clearRect(const tgfx::Rect& rect, const tgfx::Color& color) {
109-
canvas->clearRect(rect, color);
110-
}
111-
112108
void drawLine(float x0, float y0, float x1, float y1, const tgfx::Paint& paint) {
113109
canvas->drawLine(x0, y0, x1, y1, createPaint(paint));
114110
}

src/rendering/renderers/FilterRenderer.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,12 @@ void FilterRenderer::MeasureFilterBounds(tgfx::Rect* bounds, const FilterModifie
152152
}
153153
}
154154

155-
tgfx::Rect GetClipBounds(Canvas* canvas, const FilterList* filterList) {
155+
tgfx::Rect GetClipBounds(Canvas* canvas, const FilterList* filterList,
156+
const tgfx::Rect& contentBounds) {
156157
auto clip = canvas->getTotalClip();
158+
if (clip.isInverseFillType()) {
159+
return contentBounds;
160+
}
157161
auto matrix = canvas->getMatrix();
158162
if (filterList->useParentSizeInput) {
159163
tgfx::Matrix inverted = tgfx::Matrix::I();
@@ -359,7 +363,7 @@ void FilterRenderer::DrawWithFilter(Canvas* parentCanvas, const FilterModifier*
359363
auto filterList = MakeFilterList(modifier);
360364
auto contentBounds = GetContentBounds(filterList.get(), content);
361365
// 相对于content Bounds的clip Bounds
362-
auto clipBounds = GetClipBounds(parentCanvas, filterList.get());
366+
auto clipBounds = GetClipBounds(parentCanvas, filterList.get(), contentBounds);
363367

364368
auto contentScale = GetContentScale(parentCanvas, filterList->scaleFactorLimit,
365369
GetScaleFactor(filterList.get(), contentBounds));

0 commit comments

Comments
 (0)