diff --git a/shell/platform/darwin/macos/BUILD.gn b/shell/platform/darwin/macos/BUILD.gn index b24f9db330c19..08fee8588d53b 100644 --- a/shell/platform/darwin/macos/BUILD.gn +++ b/shell/platform/darwin/macos/BUILD.gn @@ -180,6 +180,9 @@ executable("flutter_desktop_darwin_unittests") { "framework/Source/FlutterEngineTestUtils.mm", "framework/Source/FlutterFrameBufferProviderUnittests.mm", "framework/Source/FlutterGLCompositorUnittests.mm", + "framework/Source/FlutterGLTestUtils.h", + "framework/Source/FlutterGLTestUtils.mm", + "framework/Source/FlutterIOSurfaceHolderUnittests.mm", "framework/Source/FlutterKeyboardManagerUnittests.mm", "framework/Source/FlutterMetalCompositorUnittests.mm", "framework/Source/FlutterMetalRendererTest.mm", diff --git a/shell/platform/darwin/macos/framework/Source/FlutterFrameBufferProviderUnittests.mm b/shell/platform/darwin/macos/framework/Source/FlutterFrameBufferProviderUnittests.mm index 5de56df9a73c3..c3657bf4d5fbf 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterFrameBufferProviderUnittests.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterFrameBufferProviderUnittests.mm @@ -5,18 +5,16 @@ #import #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterFrameBufferProvider.h" -#import "flutter/testing/testing.h" +#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterGLTestUtils.h" #import +#import "flutter/testing/testing.h" + namespace flutter::testing { TEST(FlutterFrameBufferProviderTest, TestCreate) { - NSOpenGLPixelFormatAttribute attributes[] = { - NSOpenGLPFAColorSize, 24, NSOpenGLPFAAlphaSize, 8, 0, - }; - NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; - NSOpenGLContext* context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil]; + NSOpenGLContext* context = CreateTestOpenGLContext(); [context makeCurrentContext]; FlutterFrameBufferProvider* framebufferProvider = diff --git a/shell/platform/darwin/macos/framework/Source/FlutterGLTestUtils.h b/shell/platform/darwin/macos/framework/Source/FlutterGLTestUtils.h new file mode 100644 index 0000000000000..ccb325bd5df16 --- /dev/null +++ b/shell/platform/darwin/macos/framework/Source/FlutterGLTestUtils.h @@ -0,0 +1,13 @@ +// 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. + +#import + +namespace flutter::testing { + +// Returns an NSOpenGLContext with a 24-bit color + 8-bit alpha pixel +// format. +NSOpenGLContext* CreateTestOpenGLContext(); + +} // namespace flutter::testing diff --git a/shell/platform/darwin/macos/framework/Source/FlutterGLTestUtils.mm b/shell/platform/darwin/macos/framework/Source/FlutterGLTestUtils.mm new file mode 100644 index 0000000000000..354eb73400616 --- /dev/null +++ b/shell/platform/darwin/macos/framework/Source/FlutterGLTestUtils.mm @@ -0,0 +1,19 @@ +// 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. + +#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterGLTestUtils.h" + +#import + +namespace flutter::testing { + +NSOpenGLContext* CreateTestOpenGLContext() { + NSOpenGLPixelFormatAttribute attributes[] = { + NSOpenGLPFAColorSize, 24, NSOpenGLPFAAlphaSize, 8, 0, + }; + NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; + return [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil]; +} + +} // flutter::testing diff --git a/shell/platform/darwin/macos/framework/Source/FlutterIOSurfaceHolderUnittests.mm b/shell/platform/darwin/macos/framework/Source/FlutterIOSurfaceHolderUnittests.mm new file mode 100644 index 0000000000000..1f32b8fb50db6 --- /dev/null +++ b/shell/platform/darwin/macos/framework/Source/FlutterIOSurfaceHolderUnittests.mm @@ -0,0 +1,43 @@ +// 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. + +#import + +#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterGLTestUtils.h" +#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterIOSurfaceHolder.h" + +#import +#import "flutter/testing/testing.h" + +namespace flutter::testing { + +TEST(FlutterIOSurfaceHolder, BindSurface) { + NSOpenGLContext* context = CreateTestOpenGLContext(); + + [context makeCurrentContext]; + + GLuint fbo; + GLuint tex; + + glGenFramebuffers(1, &fbo); + glGenTextures(1, &tex); + + FlutterIOSurfaceHolder* ioSurfaceHolder = [[FlutterIOSurfaceHolder alloc] init]; + + [ioSurfaceHolder bindSurfaceToTexture:tex fbo:fbo size:CGSizeMake(1.0f, 2.0f)]; + + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + EXPECT_TRUE(status == GL_FRAMEBUFFER_COMPLETE); + + IOSurfaceRef ioSurface = [ioSurfaceHolder ioSurface]; + EXPECT_EQ(IOSurfaceGetWidth(ioSurface), 1u); + EXPECT_EQ(IOSurfaceGetHeight(ioSurface), 2u); + + [ioSurfaceHolder recreateIOSurfaceWithSize:CGSizeMake(3.0f, 4.0f)]; + + EXPECT_EQ(IOSurfaceGetWidth(ioSurface), 3u); + EXPECT_EQ(IOSurfaceGetHeight(ioSurface), 4u); +} + +} // flutter::testing