|
4 | 4 | #include "flutter/shell/common/thread_host.h"
|
5 | 5 | #include "flutter/shell/platform/android/android_context_gl.h"
|
6 | 6 | #include "flutter/shell/platform/android/android_environment_gl.h"
|
| 7 | +#include "flutter/shell/platform/android/android_surface_gl.h" |
| 8 | +#include "flutter/shell/platform/android/jni/platform_view_android_jni.h" |
| 9 | +#include "gmock/gmock.h" |
7 | 10 | #include "gtest/gtest.h"
|
8 | 11 |
|
9 | 12 | namespace flutter {
|
10 | 13 | namespace testing {
|
11 | 14 | namespace android {
|
12 | 15 | namespace {
|
| 16 | +class MockPlatformViewAndroidJNI : public PlatformViewAndroidJNI { |
| 17 | + public: |
| 18 | + MOCK_METHOD2(FlutterViewHandlePlatformMessage, |
| 19 | + void(std::unique_ptr<flutter::PlatformMessage> message, |
| 20 | + int responseId)); |
| 21 | + MOCK_METHOD2(FlutterViewHandlePlatformMessageResponse, |
| 22 | + void(int responseId, std::unique_ptr<fml::Mapping> data)); |
| 23 | + MOCK_METHOD3(FlutterViewUpdateSemantics, |
| 24 | + void(std::vector<uint8_t> buffer, |
| 25 | + std::vector<std::string> strings, |
| 26 | + std::vector<std::vector<uint8_t>> string_attribute_args)); |
| 27 | + MOCK_METHOD2(FlutterViewUpdateCustomAccessibilityActions, |
| 28 | + void(std::vector<uint8_t> actions_buffer, |
| 29 | + std::vector<std::string> strings)); |
| 30 | + MOCK_METHOD0(FlutterViewOnFirstFrame, void()); |
| 31 | + MOCK_METHOD0(FlutterViewOnPreEngineRestart, void()); |
| 32 | + MOCK_METHOD2(SurfaceTextureAttachToGLContext, |
| 33 | + void(JavaLocalRef surface_texture, int textureId)); |
| 34 | + MOCK_METHOD1(SurfaceTextureUpdateTexImage, |
| 35 | + void(JavaLocalRef surface_texture)); |
| 36 | + MOCK_METHOD2(SurfaceTextureGetTransformMatrix, |
| 37 | + void(JavaLocalRef surface_texture, SkMatrix& transform)); |
| 38 | + MOCK_METHOD1(SurfaceTextureDetachFromGLContext, |
| 39 | + void(JavaLocalRef surface_texture)); |
| 40 | + MOCK_METHOD8(FlutterViewOnDisplayPlatformView, |
| 41 | + void(int view_id, |
| 42 | + int x, |
| 43 | + int y, |
| 44 | + int width, |
| 45 | + int height, |
| 46 | + int viewWidth, |
| 47 | + int viewHeight, |
| 48 | + MutatorsStack mutators_stack)); |
| 49 | + MOCK_METHOD5(FlutterViewDisplayOverlaySurface, |
| 50 | + void(int surface_id, int x, int y, int width, int height)); |
| 51 | + MOCK_METHOD0(FlutterViewBeginFrame, void()); |
| 52 | + MOCK_METHOD0(FlutterViewEndFrame, void()); |
| 53 | + MOCK_METHOD0(FlutterViewCreateOverlaySurface, |
| 54 | + std::unique_ptr<PlatformViewAndroidJNI::OverlayMetadata>()); |
| 55 | + MOCK_METHOD0(FlutterViewDestroyOverlaySurfaces, void()); |
| 56 | + MOCK_METHOD1(FlutterViewComputePlatformResolvedLocale, |
| 57 | + std::unique_ptr<std::vector<std::string>>( |
| 58 | + std::vector<std::string> supported_locales_data)); |
| 59 | + MOCK_METHOD0(GetDisplayRefreshRate, double()); |
| 60 | + MOCK_METHOD1(RequestDartDeferredLibrary, bool(int loading_unit_id)); |
| 61 | +}; |
| 62 | + |
13 | 63 | TaskRunners MakeTaskRunners(const std::string& thread_label,
|
14 | 64 | const ThreadHost& thread_host) {
|
15 | 65 | fml::MessageLoop::EnsureInitializedForCurrentThread();
|
@@ -62,6 +112,52 @@ TEST(AndroidContextGl, CreateSingleThread) {
|
62 | 112 | context.reset();
|
63 | 113 | EXPECT_TRUE(main_context->abandoned());
|
64 | 114 | }
|
| 115 | + |
| 116 | +TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNotNull) { |
| 117 | + GrMockOptions main_context_options; |
| 118 | + sk_sp<GrDirectContext> main_context = |
| 119 | + GrDirectContext::MakeMock(&main_context_options); |
| 120 | + auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>(); |
| 121 | + std::string thread_label = |
| 122 | + ::testing::UnitTest::GetInstance()->current_test_info()->name(); |
| 123 | + ThreadHost thread_host(thread_label, ThreadHost::Type::UI | |
| 124 | + ThreadHost::Type::RASTER | |
| 125 | + ThreadHost::Type::IO); |
| 126 | + TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host); |
| 127 | + auto android_context = std::make_shared<AndroidContextGL>( |
| 128 | + AndroidRenderingAPI::kOpenGLES, environment, task_runners); |
| 129 | + auto jni = std::make_shared<MockPlatformViewAndroidJNI>(); |
| 130 | + auto android_surface = |
| 131 | + std::make_unique<AndroidSurfaceGL>(android_context, jni); |
| 132 | + auto window = fml::MakeRefCounted<AndroidNativeWindow>( |
| 133 | + nullptr, /*is_fake_window=*/true); |
| 134 | + android_surface->SetNativeWindow(window); |
| 135 | + auto onscreen_surface = android_surface->GetOnscreenSurface(); |
| 136 | + EXPECT_NE(onscreen_surface, nullptr); |
| 137 | + android_surface->CreateSnapshotSurface(); |
| 138 | + EXPECT_EQ(onscreen_surface, android_surface->GetOnscreenSurface()); |
| 139 | +} |
| 140 | + |
| 141 | +TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNull) { |
| 142 | + GrMockOptions main_context_options; |
| 143 | + sk_sp<GrDirectContext> main_context = |
| 144 | + GrDirectContext::MakeMock(&main_context_options); |
| 145 | + auto environment = fml::MakeRefCounted<AndroidEnvironmentGL>(); |
| 146 | + std::string thread_label = |
| 147 | + ::testing::UnitTest::GetInstance()->current_test_info()->name(); |
| 148 | + ThreadHost thread_host(thread_label, ThreadHost::Type::UI | |
| 149 | + ThreadHost::Type::RASTER | |
| 150 | + ThreadHost::Type::IO); |
| 151 | + TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host); |
| 152 | + auto android_context = std::make_shared<AndroidContextGL>( |
| 153 | + AndroidRenderingAPI::kOpenGLES, environment, task_runners); |
| 154 | + auto jni = std::make_shared<MockPlatformViewAndroidJNI>(); |
| 155 | + auto android_surface = |
| 156 | + std::make_unique<AndroidSurfaceGL>(android_context, jni); |
| 157 | + EXPECT_EQ(android_surface->GetOnscreenSurface(), nullptr); |
| 158 | + android_surface->CreateSnapshotSurface(); |
| 159 | + EXPECT_NE(android_surface->GetOnscreenSurface(), nullptr); |
| 160 | +} |
65 | 161 | } // namespace android
|
66 | 162 | } // namespace testing
|
67 | 163 | } // namespace flutter
|
0 commit comments