1// Copyright 2013 The Flutter Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h" 6 7#include "flutter/common/settings.h" 8#include "flutter/common/task_runners.h" 9#include "flutter/flow/layers/layer_tree.h" 10#include "flutter/fml/platform/darwin/cf_utils.h" 11#include "flutter/fml/synchronization/waitable_event.h" 12#include "flutter/fml/trace_event.h" 13#include "flutter/shell/common/platform_view.h" 14#include "flutter/shell/common/rasterizer.h" 15#include "flutter/shell/platform/darwin/ios/ios_surface_gl.h" 16#include "flutter/shell/platform/darwin/ios/ios_surface_software.h" 17#include "third_party/skia/include/utils/mac/SkCGUtils.h" 18 19// This is mostly a duplication of FlutterView. 20// TODO(amirh): once GL support is in evaluate if we can merge this with FlutterView. 21@implementation FlutterOverlayView 22 23- (instancetype)initWithFrame:(CGRect)frame { 24 @throw([NSException exceptionWithName:@"FlutterOverlayView must init or initWithContentsScale" 25 reason:nil 26 userInfo:nil]); 27} 28 29- (instancetype)initWithCoder:(NSCoder*)aDecoder { 30 @throw([NSException exceptionWithName:@"FlutterOverlayView must init or initWithContentsScale" 31 reason:nil 32 userInfo:nil]); 33} 34 35- (instancetype)init { 36 self = [super initWithFrame:CGRectZero]; 37 38 if (self) { 39 self.layer.opaque = NO; 40 self.userInteractionEnabled = NO; 41 } 42 43 return self; 44} 45 46- (instancetype)initWithContentsScale:(CGFloat)contentsScale { 47 self = [self init]; 48 49 if ([self.layer isKindOfClass:[CAEAGLLayer class]]) { 50 CAEAGLLayer* layer = reinterpret_cast<CAEAGLLayer*>(self.layer); 51 layer.allowsGroupOpacity = NO; 52 layer.contentsScale = contentsScale; 53 layer.rasterizationScale = contentsScale; 54 } 55 56 return self; 57} 58 59+ (Class)layerClass { 60#if TARGET_IPHONE_SIMULATOR 61 return [CALayer class]; 62#else // TARGET_IPHONE_SIMULATOR 63 return [CAEAGLLayer class]; 64#endif // TARGET_IPHONE_SIMULATOR 65} 66 67- (std::unique_ptr<flutter::IOSSurface>)createSoftwareSurface { 68 fml::scoped_nsobject<CALayer> layer(reinterpret_cast<CALayer*>([self.layer retain])); 69 return std::make_unique<flutter::IOSSurfaceSoftware>(std::move(layer), nullptr); 70} 71 72- (std::unique_ptr<flutter::IOSSurfaceGL>)createGLSurfaceWithContext: 73 (std::shared_ptr<flutter::IOSGLContext>)gl_context { 74 fml::scoped_nsobject<CAEAGLLayer> eagl_layer(reinterpret_cast<CAEAGLLayer*>([self.layer retain])); 75 // TODO(amirh): We can lower this to iOS 8.0 once we have a Metal rendering backend. 76 // https://github.com/flutter/flutter/issues/24132 77 if (@available(iOS 9.0, *)) { 78 eagl_layer.get().presentsWithTransaction = YES; 79 } 80 return std::make_unique<flutter::IOSSurfaceGL>(eagl_layer, std::move(gl_context)); 81} 82 83// TODO(amirh): implement drawLayer to suppoer snapshotting. 84 85@end 86