Skip to content

Commit 83bf65d

Browse files
bwikbsswift-kim
authored andcommitted
Add flutter_tizen_texture_registrar unittest (#141)
Signed-off-by: MuHong Byun <[email protected]>
1 parent ada25dd commit 83bf65d

9 files changed

+238
-8
lines changed

shell/platform/tizen/BUILD.gn

+3
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ template("embedder_executable") {
245245
"channels/localization_channel_stub.cc",
246246
"channels/platform_channel_stub.cc",
247247
"channels/settings_channel_stub.cc",
248+
"external_texture_pixel_gl_stub.cc",
249+
"external_texture_surface_gl_stub.cc",
248250
"tizen_log_stub.cc",
249251
"tizen_renderer_evas_gl.cc",
250252
]
@@ -303,6 +305,7 @@ embedder_executable("flutter_tizen_unittests") {
303305

304306
sources = [
305307
"flutter_tizen_engine_unittest.cc",
308+
"flutter_tizen_texture_registrar_unittests.cc",
306309
"testing/mock_engine.cc",
307310
]
308311

shell/platform/tizen/external_texture_pixel_gl.cc

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ ExternalTexturePixelGL::ExternalTexturePixelGL(
4545
user_data_(user_data) {}
4646

4747
bool ExternalTexturePixelGL::CopyPixelBuffer(size_t& width, size_t& height) {
48+
if (!texture_callback_) {
49+
return false;
50+
}
51+
4852
const FlutterDesktopPixelBuffer* pixel_buffer =
4953
texture_callback_(width, height, user_data_);
5054

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/shell/platform/tizen/external_texture_pixel_gl.h"
6+
7+
namespace flutter {
8+
9+
ExternalTexturePixelGL::ExternalTexturePixelGL(
10+
FlutterDesktopPixelBufferTextureCallback texture_callback,
11+
void* user_data)
12+
: ExternalTexture(),
13+
texture_callback_(texture_callback),
14+
user_data_(user_data) {}
15+
16+
bool ExternalTexturePixelGL::PopulateTexture(
17+
size_t width,
18+
size_t height,
19+
FlutterOpenGLTexture* opengl_texture) {
20+
return CopyPixelBuffer(width, height);
21+
}
22+
23+
bool ExternalTexturePixelGL::CopyPixelBuffer(size_t& width, size_t& height) {
24+
if (texture_callback_ && user_data_) {
25+
return true;
26+
}
27+
return false;
28+
}
29+
} // namespace flutter

shell/platform/tizen/external_texture_surface_gl.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ bool ExternalTextureSurfaceGL::PopulateTexture(
5454
size_t width,
5555
size_t height,
5656
FlutterOpenGLTexture* opengl_texture) {
57+
if (!texture_callback_) {
58+
return false;
59+
}
5760
const FlutterDesktopGpuBuffer* gpu_buffer =
5861
texture_callback_(width, height, user_data_);
5962
if (!gpu_buffer) {
@@ -153,7 +156,9 @@ bool ExternalTextureSurfaceGL::PopulateTexture(
153156
}
154157

155158
void ExternalTextureSurfaceGL::OnDestruction() {
156-
destruction_callback_(user_data_);
159+
if (destruction_callback_) {
160+
destruction_callback_(user_data_);
161+
}
157162
}
158163

159164
} // namespace flutter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "external_texture_surface_gl.h"
6+
7+
namespace flutter {
8+
9+
ExternalTextureSurfaceGL::ExternalTextureSurfaceGL(
10+
FlutterDesktopGpuBufferTextureCallback texture_callback,
11+
FlutterDesktopGpuBufferDestructionCallback destruction_callback,
12+
void* user_data)
13+
: ExternalTexture(),
14+
texture_callback_(texture_callback),
15+
destruction_callback_(destruction_callback),
16+
user_data_(user_data) {}
17+
18+
ExternalTextureSurfaceGL::~ExternalTextureSurfaceGL() {
19+
state_.release();
20+
}
21+
22+
bool ExternalTextureSurfaceGL::PopulateTexture(
23+
size_t width,
24+
size_t height,
25+
FlutterOpenGLTexture* opengl_texture) {
26+
if (texture_callback_ && destruction_callback_ && user_data_) {
27+
return true;
28+
}
29+
return false;
30+
}
31+
32+
void ExternalTextureSurfaceGL::OnDestruction() {
33+
if (destruction_callback_) {
34+
destruction_callback_(user_data_);
35+
}
36+
}
37+
38+
} // namespace flutter

shell/platform/tizen/flutter_tizen_engine.h

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class FlutterTizenEngine : public TizenRenderer::Delegate {
142142
std::unique_ptr<PlatformViewChannel> platform_view_channel;
143143

144144
private:
145+
friend class EngineModifier;
146+
145147
// Whether the engine is running in headed or headless mode.
146148
bool IsHeaded() { return renderer != nullptr; }
147149

shell/platform/tizen/flutter_tizen_texture_registrar.cc

-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
#include <iostream>
88
#include <mutex>
99

10-
#ifndef __X64_SHELL__
1110
#include "flutter/shell/platform/tizen/external_texture_pixel_gl.h"
1211
#include "flutter/shell/platform/tizen/external_texture_surface_gl.h"
13-
#endif
1412
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
1513
#include "flutter/shell/platform/tizen/tizen_log.h"
1614

@@ -90,10 +88,6 @@ bool FlutterTizenTextureRegistrar::PopulateTexture(
9088
std::unique_ptr<ExternalTexture>
9189
FlutterTizenTextureRegistrar::CreateExternalTexture(
9290
const FlutterDesktopTextureInfo* texture_info) {
93-
#ifdef __X64_SHELL__
94-
FT_UNIMPLEMENTED();
95-
return nullptr;
96-
#else
9791
switch (texture_info->type) {
9892
case kFlutterDesktopPixelBufferTexture:
9993
return std::make_unique<ExternalTexturePixelGL>(
@@ -110,7 +104,6 @@ FlutterTizenTextureRegistrar::CreateExternalTexture(
110104
FT_LOGE("Invalid texture type.");
111105
return nullptr;
112106
}
113-
#endif
114107
}
115108

116109
} // namespace flutter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <iostream>
6+
7+
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
8+
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
9+
#include "flutter/shell/platform/tizen/flutter_tizen_texture_registrar.h"
10+
#include "flutter/shell/platform/tizen/testing/engine_modifier.h"
11+
#include "gtest/gtest.h"
12+
13+
namespace flutter {
14+
namespace testing {
15+
16+
class FlutterTizenTextureRegistrarTest : public ::testing::Test {
17+
public:
18+
FlutterTizenTextureRegistrarTest() {
19+
ecore_init();
20+
elm_init(0, nullptr);
21+
}
22+
23+
protected:
24+
void SetUp() {
25+
FlutterDesktopEngineProperties engine_prop = {};
26+
engine_prop.assets_path = "foo/flutter_assets";
27+
engine_prop.icu_data_path = "foo/icudtl.dat";
28+
engine_prop.aot_library_path = "foo/libapp.so";
29+
30+
FlutterProjectBundle project(engine_prop);
31+
auto engine = std::make_unique<FlutterTizenEngine>(project);
32+
engine_ = engine.release();
33+
}
34+
35+
void TearDown() {
36+
if (engine_) {
37+
delete engine_;
38+
}
39+
engine_ = nullptr;
40+
}
41+
42+
FlutterTizenEngine* engine_;
43+
};
44+
45+
TEST_F(FlutterTizenTextureRegistrarTest, CreateDestroy) {
46+
FlutterTizenTextureRegistrar registrar(engine_);
47+
48+
EXPECT_TRUE(true);
49+
}
50+
51+
TEST_F(FlutterTizenTextureRegistrarTest, RegisterUnregisterTexture) {
52+
EngineModifier modifier(engine_);
53+
54+
FlutterTizenTextureRegistrar registrar(engine_);
55+
56+
FlutterDesktopTextureInfo texture_info = {};
57+
texture_info.type = kFlutterDesktopPixelBufferTexture;
58+
texture_info.pixel_buffer_config.callback =
59+
[](size_t width, size_t height,
60+
void* user_data) -> const FlutterDesktopPixelBuffer* {
61+
return nullptr;
62+
};
63+
64+
int64_t registered_texture_id = 0;
65+
bool register_called = false;
66+
modifier.embedder_api().RegisterExternalTexture = MOCK_ENGINE_PROC(
67+
RegisterExternalTexture, ([&register_called, &registered_texture_id](
68+
auto engine, auto texture_id) {
69+
register_called = true;
70+
registered_texture_id = texture_id;
71+
return kSuccess;
72+
}));
73+
74+
bool unregister_called = false;
75+
modifier.embedder_api().UnregisterExternalTexture = MOCK_ENGINE_PROC(
76+
UnregisterExternalTexture, ([&unregister_called, &registered_texture_id](
77+
auto engine, auto texture_id) {
78+
unregister_called = true;
79+
EXPECT_EQ(registered_texture_id, texture_id);
80+
return kSuccess;
81+
}));
82+
83+
bool mark_frame_available_called = false;
84+
modifier.embedder_api().MarkExternalTextureFrameAvailable =
85+
MOCK_ENGINE_PROC(MarkExternalTextureFrameAvailable,
86+
([&mark_frame_available_called, &registered_texture_id](
87+
auto engine, auto texture_id) {
88+
mark_frame_available_called = true;
89+
EXPECT_EQ(registered_texture_id, texture_id);
90+
return kSuccess;
91+
}));
92+
93+
auto texture_id = registrar.RegisterTexture(&texture_info);
94+
EXPECT_TRUE(register_called);
95+
EXPECT_NE(texture_id, -1);
96+
EXPECT_EQ(texture_id, registered_texture_id);
97+
98+
EXPECT_TRUE(registrar.MarkTextureFrameAvailable(texture_id));
99+
EXPECT_TRUE(mark_frame_available_called);
100+
101+
EXPECT_TRUE(registrar.UnregisterTexture(texture_id));
102+
EXPECT_TRUE(unregister_called);
103+
}
104+
105+
TEST_F(FlutterTizenTextureRegistrarTest, RegisterUnknownTextureType) {
106+
EngineModifier modifier(engine_);
107+
108+
FlutterTizenTextureRegistrar registrar(engine_);
109+
110+
FlutterDesktopTextureInfo texture_info = {};
111+
texture_info.type = static_cast<FlutterDesktopTextureType>(1234);
112+
113+
auto texture_id = registrar.RegisterTexture(&texture_info);
114+
115+
EXPECT_EQ(texture_id, -1);
116+
}
117+
118+
TEST_F(FlutterTizenTextureRegistrarTest, PopulateInvalidTexture) {
119+
FlutterTizenTextureRegistrar registrar(engine_);
120+
121+
auto result = registrar.PopulateTexture(1, 640, 480, nullptr);
122+
EXPECT_FALSE(result);
123+
}
124+
125+
} // namespace testing
126+
} // namespace flutter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Copyright 2013 The Flutter Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
6+
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
7+
8+
namespace flutter {
9+
10+
// A test utility class providing the ability to access and alter various
11+
// private fields in an Engine instance.
12+
//
13+
// This simply provides a way to access the normally-private embedder proc
14+
// table, so the lifetime of any changes made to the proc table is that of the
15+
// engine object, not this helper.
16+
class EngineModifier {
17+
public:
18+
explicit EngineModifier(FlutterTizenEngine* engine) : engine_(engine) {}
19+
20+
// Returns the engine's embedder API proc table, allowing for modification.
21+
//
22+
// Modifications are to the engine, and will last for the lifetime of the
23+
// engine unless overwritten again.
24+
FlutterEngineProcTable& embedder_api() { return engine_->embedder_api_; }
25+
26+
private:
27+
FlutterTizenEngine* engine_;
28+
};
29+
30+
} // namespace flutter

0 commit comments

Comments
 (0)