forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios] Adds an API for running Dart code without a PlatformViewIOS (fl…
- Loading branch information
Showing
10 changed files
with
215 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/shell/common/null_platform_view.h" | ||
|
||
#include "flutter/shell/common/null_rasterizer.h" | ||
#include "flutter/shell/common/shell.h" | ||
|
||
namespace shell { | ||
|
||
NullPlatformView::NullPlatformView() | ||
: PlatformView(std::make_unique<NullRasterizer>()), weak_factory_(this) {} | ||
|
||
void NullPlatformView::Attach() { | ||
CreateEngine(); | ||
} | ||
|
||
NullPlatformView::~NullPlatformView() = default; | ||
|
||
fxl::WeakPtr<NullPlatformView> NullPlatformView::GetWeakPtr() { | ||
return weak_factory_.GetWeakPtr(); | ||
} | ||
|
||
bool NullPlatformView::ResourceContextMakeCurrent() { | ||
return false; | ||
} | ||
|
||
// Hot-reload of the null platform view is not supported. | ||
void NullPlatformView::RunFromSource(const std::string& assets_directory, | ||
const std::string& main, | ||
const std::string& packages) {} | ||
|
||
} // namespace shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef COMMON_NULL_PLATFORM_VIEW_H_ | ||
#define COMMON_NULL_PLATFORM_VIEW_H_ | ||
|
||
#include "flutter/shell/common/platform_view.h" | ||
#include "lib/fxl/macros.h" | ||
#include "lib/fxl/memory/weak_ptr.h" | ||
|
||
namespace shell { | ||
|
||
class NullPlatformView : public PlatformView { | ||
public: | ||
NullPlatformView(); | ||
|
||
~NullPlatformView(); | ||
|
||
fxl::WeakPtr<NullPlatformView> GetWeakPtr(); | ||
|
||
virtual void Attach() override; | ||
|
||
bool ResourceContextMakeCurrent() override; | ||
|
||
void RunFromSource(const std::string& assets_directory, | ||
const std::string& main, | ||
const std::string& packages) override; | ||
|
||
private: | ||
fxl::WeakPtrFactory<NullPlatformView> weak_factory_; | ||
|
||
FXL_DISALLOW_COPY_AND_ASSIGN(NullPlatformView); | ||
}; | ||
|
||
} // namespace shell | ||
|
||
#endif // COMMON_NULL_PLATFORM_VIEW_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
shell/platform/darwin/ios/framework/Headers/FlutterHeadlessDartRunner.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_FLUTTERHEADLESSDARTRUNNER_H_ | ||
#define FLUTTER_FLUTTERHEADLESSDARTRUNNER_H_ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#include "FlutterDartProject.h" | ||
#include "FlutterMacros.h" | ||
|
||
/** | ||
The FlutterHeadlessDartRunner runs Flutter Dart code with a null rasterizer, | ||
and no native drawing surface. It is appropriate for use in running Dart | ||
code e.g. in the background from a plugin. | ||
*/ | ||
FLUTTER_EXPORT | ||
@interface FlutterHeadlessDartRunner : NSObject | ||
|
||
/** | ||
Runs a Dart function on an Isolate that is not the main application's Isolate. | ||
The first call will create a new Isolate. Subsequent calls will reuse that | ||
Isolate. The Isolate is destroyed when the FlutterHeadlessDartRunner is | ||
destroyed. | ||
- Parameter entrypoint: The name of a top-level function from the same Dart | ||
library that contains the app's main() function. | ||
*/ | ||
- (void)runWithEntrypoint:(NSString*)entrypoint; | ||
|
||
@end | ||
|
||
#endif // FLUTTER_FLUTTERHEADLESSDARTRUNNER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
shell/platform/darwin/ios/framework/Source/FlutterHeadlessDartRunner.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2017 The Chromium 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/ios/framework/Headers/FlutterHeadlessDartRunner.h" | ||
|
||
#include <memory> | ||
|
||
#include "flutter/fml/platform/darwin/scoped_nsobject.h" | ||
#include "flutter/shell/common/null_platform_view.h" | ||
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h" | ||
|
||
@interface FlutterHeadlessDartRunner () | ||
@end | ||
|
||
@implementation FlutterHeadlessDartRunner { | ||
fml::scoped_nsprotocol<FlutterDartProject*> _dartProject; | ||
std::shared_ptr<shell::NullPlatformView> _platformView; | ||
} | ||
|
||
- (instancetype)init { | ||
_dartProject.reset([[FlutterDartProject alloc] initFromDefaultSourceForConfiguration]); | ||
_platformView = std::make_shared<shell::NullPlatformView>(); | ||
_platformView->Attach(); | ||
return self; | ||
} | ||
|
||
- (void)runWithEntrypoint:(NSString*)entrypoint { | ||
const enum VMType type = Dart_IsPrecompiledRuntime() ? VMTypePrecompilation : VMTypeInterpreter; | ||
[_dartProject launchInEngine:&_platformView->engine() | ||
withEntrypoint:entrypoint | ||
embedderVMType:type | ||
result:^(BOOL success, NSString* message) { | ||
if (!success) | ||
NSLog(@"%@", message); | ||
}]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters