forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 17
Add flutter_tizen_texture_registrar unittest #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add flutter_tizen_texture_registrar unittest
Signed-off-by: MuHong Byun <[email protected]>
- Loading branch information
commit b4dafee566939a8784b80d7c6fee8c103c601c5f
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,77 @@ | ||
| // 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" | ||
|
|
||
| #ifdef TIZEN_RENDERER_EVAS_GL | ||
| #undef EFL_BETA_API_SUPPORT | ||
| #include "tizen_evas_gl_helper.h" | ||
| extern Evas_GL* g_evas_gl; | ||
| EVAS_GL_GLOBAL_GLES3_DECLARE(); | ||
| #else | ||
| #include <EGL/egl.h> | ||
| #include <EGL/eglext.h> | ||
| #include <GLES2/gl2ext.h> | ||
| #include <GLES3/gl32.h> | ||
| #endif | ||
bwikbs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| namespace flutter { | ||
|
|
||
| ExternalTexturePixelGL::ExternalTexturePixelGL( | ||
bwikbs marked this conversation as resolved.
Show resolved
Hide resolved
bwikbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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) { | ||
| if (!CopyPixelBuffer(width, height)) { | ||
| return false; | ||
| } | ||
|
|
||
| // Populate the texture object used by the engine. | ||
| opengl_texture->target = GL_TEXTURE_2D; | ||
| opengl_texture->name = state_->gl_texture; | ||
| opengl_texture->format = GL_RGBA8; | ||
| opengl_texture->destruction_callback = nullptr; | ||
| opengl_texture->user_data = nullptr; | ||
| opengl_texture->width = width; | ||
| opengl_texture->height = height; | ||
| return true; | ||
| } | ||
|
|
||
| bool ExternalTexturePixelGL::CopyPixelBuffer(size_t& width, size_t& height) { | ||
| if (!texture_callback_) { | ||
| return false; | ||
| } | ||
|
|
||
| const FlutterDesktopPixelBuffer* pixel_buffer = | ||
| texture_callback_(width, height, user_data_); | ||
bwikbs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (!pixel_buffer || !pixel_buffer->buffer) { | ||
| return false; | ||
| } | ||
|
|
||
| width = pixel_buffer->width; | ||
| height = pixel_buffer->height; | ||
|
|
||
| if (state_->gl_texture == 0) { | ||
| glGenTextures(1, &state_->gl_texture); | ||
| glBindTexture(GL_TEXTURE_2D, state_->gl_texture); | ||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); | ||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); | ||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
| } else { | ||
| glBindTexture(GL_TEXTURE_2D, state_->gl_texture); | ||
| } | ||
| glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, | ||
| pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, | ||
| pixel_buffer->buffer); | ||
| return true; | ||
| } | ||
| } // namespace flutter | ||
This file contains hidden or 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 hidden or 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,53 @@ | ||
| // 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" | ||
|
|
||
| #include "flutter/shell/platform/common/public/flutter_texture_registrar.h" | ||
| #include "flutter/shell/platform/tizen/tizen_log.h" | ||
bwikbs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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_) { | ||
| return false; | ||
| } | ||
|
|
||
| const FlutterDesktopGpuBuffer* gpu_buffer = | ||
| texture_callback_(width, height, user_data_); | ||
bwikbs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!gpu_buffer) { | ||
| FT_LOGI("[texture id:%ld] gpu_buffer is null", texture_id_); | ||
| return false; | ||
| } | ||
| if (!gpu_buffer->buffer) { | ||
| FT_LOGI("[texture id:%ld] tbm_surface_ is null", texture_id_); | ||
| return false; | ||
| } | ||
| FT_UNIMPLEMENTED(); | ||
| return false; | ||
| } | ||
|
|
||
| void ExternalTextureSurfaceGL::OnDestruction() { | ||
| if (destruction_callback_) { | ||
| destruction_callback_(user_data_); | ||
| } | ||
| } | ||
|
|
||
| } // namespace flutter | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,28 @@ | ||
| // Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
|
|
||
bwikbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.