forked from Tencent/libpag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPAGSurfaceTest.cpp
125 lines (118 loc) · 4.93 KB
/
PAGSurfaceTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// 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 "framework/pag_test.h"
#include "framework/utils/PAGTestUtils.h"
#include "gpu/opengl/GLCaps.h"
#include "gpu/opengl/GLUtil.h"
#include "platform/NativeGLDevice.h"
#include "rendering/Drawable.h"
namespace pag {
PAG_TEST_SUIT(PAGSurfaceTest)
/**
* 用例描述: 测试 PAGSurface 数据同步
*/
PAG_TEST(PAGSurfaceTest, FromTexture_ID82382683) {
auto pagFile = PAGFile::Load("../resources/apitest/test.pag");
int width = pagFile->width();
int height = pagFile->height();
auto device = NativeGLDevice::Make();
auto context = device->lockContext();
ASSERT_TRUE(context != nullptr);
auto gl = GLContext::Unwrap(context);
auto glVersion = gl->caps->version;
GLTextureInfo textureInfo;
CreateTexture(gl, width, height, &textureInfo);
auto backendTexture = BackendTexture(textureInfo, width, height);
auto pagSurface = PAGSurface::MakeFrom(backendTexture, ImageOrigin::TopLeft);
auto nativeHandle = NativeGLDevice::GetCurrentNativeHandle();
device->unlock();
auto glDevice = std::static_pointer_cast<GLDevice>(pagSurface->drawable->getDevice());
EXPECT_TRUE(glDevice->sharableWith(nativeHandle));
auto drawable = std::make_shared<TextureDrawable>(device, backendTexture, ImageOrigin::TopLeft);
auto pagSurface2 = PAGSurface::MakeFrom(drawable);
auto pagPlayer2 = std::make_shared<PAGPlayer>();
pagPlayer2->setSurface(pagSurface2);
pagPlayer2->setComposition(pagFile);
pagPlayer2->setProgress(0.1);
BackendSemaphore semaphore;
EXPECT_FALSE(pagPlayer2->wait(semaphore));
semaphore.initGL(nullptr);
EXPECT_FALSE(pagPlayer2->wait(semaphore));
semaphore = {};
pagPlayer2->flushAndSignalSemaphore(&semaphore);
if (glVersion < GL_VER(3, 0)) {
EXPECT_FALSE(semaphore.isInitialized());
} else {
EXPECT_TRUE(semaphore.isInitialized());
EXPECT_NE(semaphore.glSync(), nullptr);
auto pagPlayer = std::make_shared<PAGPlayer>();
pagPlayer->setComposition(pagFile);
pagPlayer->setSurface(pagSurface);
pagPlayer->setProgress(0.3);
EXPECT_TRUE(pagPlayer->wait(semaphore));
semaphore = {};
pagPlayer->flushAndSignalSemaphore(&semaphore);
EXPECT_TRUE(semaphore.isInitialized());
EXPECT_NE(semaphore.glSync(), nullptr);
EXPECT_TRUE(pagPlayer2->wait(semaphore));
auto md5 = DumpMD5(pagSurface2);
PAGTestEnvironment::DumpJson["PAGSurfaceTest"]["FromTexture_ID82382683"] = md5;
#ifdef COMPARE_JSON_PATH
auto compareMD5 = PAGTestEnvironment::CompareJson["PAGSurfaceTest"]["FromTexture_ID82382683"];
TraceIf(pagSurface2, "../test/out/FromTexture_ID82382683.png", md5 != compareMD5);
EXPECT_EQ(compareMD5.get<std::string>(), md5);
#endif
}
}
/**
* 用例描述: 遮罩使用屏幕坐标系时origin不一致的情况
*/
PAG_TEST(PAGSurfaceTest, mask_ID85767971) {
auto pagFile = PAGFile::Load("../assets/test2.pag");
auto width = pagFile->width();
auto height = pagFile->height();
auto device = NativeGLDevice::Make();
auto context = device->lockContext();
ASSERT_TRUE(context != nullptr);
auto gl = GLContext::Unwrap(context);
GLTextureInfo textureInfo;
CreateTexture(gl, width, height, &textureInfo);
auto backendTexture = BackendTexture(textureInfo, width, height);
auto pagSurface = PAGSurface::MakeFrom(backendTexture, ImageOrigin::BottomLeft);
device->unlock();
auto pagPlayer = std::make_shared<PAGPlayer>();
pagPlayer->setSurface(pagSurface);
pagPlayer->setComposition(pagFile);
pagPlayer->setMatrix(Matrix::I());
pagPlayer->setProgress(0.9);
pagPlayer->flush();
auto md5 = DumpMD5(pagSurface);
PAGTestEnvironment::DumpJson["PAGSurfaceTest"]["mask_ID85767971"] = md5;
#ifdef COMPARE_JSON_PATH
auto compareMD5 = PAGTestEnvironment::CompareJson["PAGSurfaceTest"]["mask_ID85767971"];
auto path = "../test/out/mask_ID85767971.png";
TraceIf(pagSurface, path, compareMD5.get<std::string>() != md5);
EXPECT_EQ(compareMD5.get<std::string>(), md5);
#endif
context = device->lockContext();
ASSERT_TRUE(context != nullptr);
gl = GLContext::Unwrap(context);
gl->deleteTextures(1, &textureInfo.id);
device->unlock();
}
} // namespace pag