forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flutter_tizen_texture_registrar unittest (#141)
* Add flutter_tizen_texture_registrar unittest Signed-off-by: MuHong Byun <mh.byun@samsung.com> * Apply review's comment * Remove redundant code Signed-off-by: MuHong Byun <mh.byun@samsung.com> * Apply review's comment #2 Signed-off-by: MuHong Byun <mh.byun@samsung.com>
- Loading branch information
Showing
9 changed files
with
238 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/shell/platform/tizen/external_texture_pixel_gl.h" | ||
|
||
namespace flutter { | ||
|
||
ExternalTexturePixelGL::ExternalTexturePixelGL( | ||
FlutterDesktopPixelBufferTextureCallback texture_callback, | ||
void* user_data) | ||
: ExternalTexture(), | ||
texture_callback_(texture_callback), | ||
user_data_(user_data) {} | ||
|
||
bool ExternalTexturePixelGL::PopulateTexture( | ||
size_t width, | ||
size_t height, | ||
FlutterOpenGLTexture* opengl_texture) { | ||
return CopyPixelBuffer(width, height); | ||
} | ||
|
||
bool ExternalTexturePixelGL::CopyPixelBuffer(size_t& width, size_t& height) { | ||
if (texture_callback_ && user_data_) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} // namespace flutter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "external_texture_surface_gl.h" | ||
|
||
namespace flutter { | ||
|
||
ExternalTextureSurfaceGL::ExternalTextureSurfaceGL( | ||
FlutterDesktopGpuBufferTextureCallback texture_callback, | ||
FlutterDesktopGpuBufferDestructionCallback destruction_callback, | ||
void* user_data) | ||
: ExternalTexture(), | ||
texture_callback_(texture_callback), | ||
destruction_callback_(destruction_callback), | ||
user_data_(user_data) {} | ||
|
||
ExternalTextureSurfaceGL::~ExternalTextureSurfaceGL() { | ||
state_.release(); | ||
} | ||
|
||
bool ExternalTextureSurfaceGL::PopulateTexture( | ||
size_t width, | ||
size_t height, | ||
FlutterOpenGLTexture* opengl_texture) { | ||
if (texture_callback_ && destruction_callback_ && user_data_) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void ExternalTextureSurfaceGL::OnDestruction() { | ||
if (destruction_callback_) { | ||
destruction_callback_(user_data_); | ||
} | ||
} | ||
|
||
} // namespace flutter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
shell/platform/tizen/flutter_tizen_texture_registrar_unittests.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include <iostream> | ||
|
||
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h" | ||
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" | ||
#include "flutter/shell/platform/tizen/flutter_tizen_texture_registrar.h" | ||
#include "flutter/shell/platform/tizen/testing/engine_modifier.h" | ||
#include "gtest/gtest.h" | ||
|
||
namespace flutter { | ||
namespace testing { | ||
|
||
class FlutterTizenTextureRegistrarTest : public ::testing::Test { | ||
public: | ||
FlutterTizenTextureRegistrarTest() { | ||
ecore_init(); | ||
elm_init(0, nullptr); | ||
} | ||
|
||
protected: | ||
void SetUp() { | ||
FlutterDesktopEngineProperties engine_prop = {}; | ||
engine_prop.assets_path = "foo/flutter_assets"; | ||
engine_prop.icu_data_path = "foo/icudtl.dat"; | ||
engine_prop.aot_library_path = "foo/libapp.so"; | ||
|
||
FlutterProjectBundle project(engine_prop); | ||
auto engine = std::make_unique<FlutterTizenEngine>(project); | ||
engine_ = engine.release(); | ||
} | ||
|
||
void TearDown() { | ||
if (engine_) { | ||
delete engine_; | ||
} | ||
engine_ = nullptr; | ||
} | ||
|
||
FlutterTizenEngine* engine_; | ||
}; | ||
|
||
TEST_F(FlutterTizenTextureRegistrarTest, CreateDestroy) { | ||
FlutterTizenTextureRegistrar registrar(engine_); | ||
|
||
EXPECT_TRUE(true); | ||
} | ||
|
||
TEST_F(FlutterTizenTextureRegistrarTest, RegisterUnregisterTexture) { | ||
EngineModifier modifier(engine_); | ||
|
||
FlutterTizenTextureRegistrar registrar(engine_); | ||
|
||
FlutterDesktopTextureInfo texture_info = {}; | ||
texture_info.type = kFlutterDesktopPixelBufferTexture; | ||
texture_info.pixel_buffer_config.callback = | ||
[](size_t width, size_t height, | ||
void* user_data) -> const FlutterDesktopPixelBuffer* { | ||
return nullptr; | ||
}; | ||
|
||
int64_t registered_texture_id = 0; | ||
bool register_called = false; | ||
modifier.embedder_api().RegisterExternalTexture = MOCK_ENGINE_PROC( | ||
RegisterExternalTexture, ([®ister_called, ®istered_texture_id]( | ||
auto engine, auto texture_id) { | ||
register_called = true; | ||
registered_texture_id = texture_id; | ||
return kSuccess; | ||
})); | ||
|
||
bool unregister_called = false; | ||
modifier.embedder_api().UnregisterExternalTexture = MOCK_ENGINE_PROC( | ||
UnregisterExternalTexture, ([&unregister_called, ®istered_texture_id]( | ||
auto engine, auto texture_id) { | ||
unregister_called = true; | ||
EXPECT_EQ(registered_texture_id, texture_id); | ||
return kSuccess; | ||
})); | ||
|
||
bool mark_frame_available_called = false; | ||
modifier.embedder_api().MarkExternalTextureFrameAvailable = | ||
MOCK_ENGINE_PROC(MarkExternalTextureFrameAvailable, | ||
([&mark_frame_available_called, ®istered_texture_id]( | ||
auto engine, auto texture_id) { | ||
mark_frame_available_called = true; | ||
EXPECT_EQ(registered_texture_id, texture_id); | ||
return kSuccess; | ||
})); | ||
|
||
auto texture_id = registrar.RegisterTexture(&texture_info); | ||
EXPECT_TRUE(register_called); | ||
EXPECT_NE(texture_id, -1); | ||
EXPECT_EQ(texture_id, registered_texture_id); | ||
|
||
EXPECT_TRUE(registrar.MarkTextureFrameAvailable(texture_id)); | ||
EXPECT_TRUE(mark_frame_available_called); | ||
|
||
EXPECT_TRUE(registrar.UnregisterTexture(texture_id)); | ||
EXPECT_TRUE(unregister_called); | ||
} | ||
|
||
TEST_F(FlutterTizenTextureRegistrarTest, RegisterUnknownTextureType) { | ||
EngineModifier modifier(engine_); | ||
|
||
FlutterTizenTextureRegistrar registrar(engine_); | ||
|
||
FlutterDesktopTextureInfo texture_info = {}; | ||
texture_info.type = static_cast<FlutterDesktopTextureType>(1234); | ||
|
||
auto texture_id = registrar.RegisterTexture(&texture_info); | ||
|
||
EXPECT_EQ(texture_id, -1); | ||
} | ||
|
||
TEST_F(FlutterTizenTextureRegistrarTest, PopulateInvalidTexture) { | ||
FlutterTizenTextureRegistrar registrar(engine_); | ||
|
||
auto result = registrar.PopulateTexture(1, 640, 480, nullptr); | ||
EXPECT_FALSE(result); | ||
} | ||
|
||
} // namespace testing | ||
} // namespace flutter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" | ||
|
||
namespace flutter { | ||
|
||
// A test utility class providing the ability to access and alter various | ||
// private fields in an Engine instance. | ||
// | ||
// This simply provides a way to access the normally-private embedder proc | ||
// table, so the lifetime of any changes made to the proc table is that of the | ||
// engine object, not this helper. | ||
class EngineModifier { | ||
public: | ||
explicit EngineModifier(FlutterTizenEngine* engine) : engine_(engine) {} | ||
|
||
// Returns the engine's embedder API proc table, allowing for modification. | ||
// | ||
// Modifications are to the engine, and will last for the lifetime of the | ||
// engine unless overwritten again. | ||
FlutterEngineProcTable& embedder_api() { return engine_->embedder_api_; } | ||
|
||
private: | ||
FlutterTizenEngine* engine_; | ||
}; | ||
|
||
} // namespace flutter |