Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions shell/platform/darwin/macos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
#import <Foundation/Foundation.h>

#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 <OpenGL/gl.h>

#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 =
Expand Down
13 changes: 13 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FlutterGLTestUtils.h
Original file line number Diff line number Diff line change
@@ -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 <Cocoa/Cocoa.h>

namespace flutter::testing {

// Returns an NSOpenGLContext with a 24-bit color + 8-bit alpha pixel
// format.
NSOpenGLContext* CreateTestOpenGLContext();

} // namespace flutter::testing
19 changes: 19 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FlutterGLTestUtils.mm
Original file line number Diff line number Diff line change
@@ -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 <OpenGL/gl.h>

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
Original file line number Diff line number Diff line change
@@ -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 <Foundation/Foundation.h>

#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterGLTestUtils.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterIOSurfaceHolder.h"

#import <OpenGL/gl.h>
#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