Flutter macOS Embedder
FlutterSurfaceManager.mm File Reference
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h"
#import <Metal/Metal.h>
#include <algorithm>
#include "flutter/fml/logging.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurface.h"

Go to the source code of this file.

Functions

static NSColor * GetBorderColorForLayer (int layer)
 
static void UpdateContentSubLayers (CALayer *layer, IOSurfaceRef surface, CGFloat scale, CGSize surfaceSize, NSColor *borderColor, const std::vector< FlutterRect > &paintRegion)
 

Variables

static const double kIdleDelay = 1.0
 
static const int kSurfaceEvictionAge = 30
 

Function Documentation

◆ GetBorderColorForLayer()

static NSColor* GetBorderColorForLayer ( int  layer)
static

Definition at line 48 of file FlutterSurfaceManager.mm.

48  {
49  NSArray* colors = @[
50  [NSColor yellowColor],
51  [NSColor cyanColor],
52  [NSColor magentaColor],
53  [NSColor greenColor],
54  [NSColor purpleColor],
55  [NSColor orangeColor],
56  [NSColor blueColor],
57  ];
58  return colors[layer % colors.count];
59 }

◆ UpdateContentSubLayers()

static void UpdateContentSubLayers ( CALayer *  layer,
IOSurfaceRef  surface,
CGFloat  scale,
CGSize  surfaceSize,
NSColor *  borderColor,
const std::vector< FlutterRect > &  paintRegion 
)
static

Creates sublayers for given layer, each one displaying a portion of the of the surface determined by a rectangle in the provided paint region.

Definition at line 63 of file FlutterSurfaceManager.mm.

68  {
69  // Adjust sublayer count to paintRegion count.
70  while (layer.sublayers.count > paintRegion.size()) {
71  [layer.sublayers.lastObject removeFromSuperlayer];
72  }
73 
74  while (layer.sublayers.count < paintRegion.size()) {
75  CALayer* newLayer = [CALayer layer];
76  [layer addSublayer:newLayer];
77  }
78 
79  for (size_t i = 0; i < paintRegion.size(); i++) {
80  CALayer* subLayer = [layer.sublayers objectAtIndex:i];
81  const auto& rect = paintRegion[i];
82  subLayer.frame = CGRectMake(rect.left / scale, rect.top / scale,
83  (rect.right - rect.left) / scale, (rect.bottom - rect.top) / scale);
84 
85  double width = surfaceSize.width;
86  double height = surfaceSize.height;
87 
88  subLayer.contentsRect =
89  CGRectMake(rect.left / width, rect.top / height, (rect.right - rect.left) / width,
90  (rect.bottom - rect.top) / height);
91 
92  if (borderColor != nil) {
93  // Visualize sublayer
94  subLayer.borderColor = borderColor.CGColor;
95  subLayer.borderWidth = 1.0;
96  }
97 
98  subLayer.contents = (__bridge id)surface;
99  }
100 }

Variable Documentation

◆ kIdleDelay

const double kIdleDelay = 1.0
static

Definition at line 268 of file FlutterSurfaceManager.mm.

◆ kSurfaceEvictionAge

const int kSurfaceEvictionAge = 30
static

Definition at line 273 of file FlutterSurfaceManager.mm.