Flutter Engine
The Flutter Engine
scenec_main.cc
Go to the documentation of this file.
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 <filesystem>
6#include <memory>
7
8#include "flutter/fml/backtrace.h"
9#include "flutter/fml/command_line.h"
10#include "flutter/fml/file.h"
11#include "flutter/fml/mapping.h"
15#include "impeller/scene/importer/scene_flatbuffers.h"
18
19#include "third_party/flatbuffers/include/flatbuffers/flatbuffer_builder.h"
20
21namespace impeller {
22namespace scene {
23namespace importer {
24
25// Sets the file access mode of the file at path 'p' to 0644.
27 auto permissions =
28 std::filesystem::perms::owner_read | std::filesystem::perms::owner_write |
29 std::filesystem::perms::group_read | std::filesystem::perms::others_read;
30 std::error_code error;
31 std::filesystem::permissions(p, permissions, error);
32 if (error) {
33 std::cerr << "Failed to set access on file '" << p
34 << "': " << error.message() << std::endl;
35 return false;
36 }
37 return true;
38}
39
40bool Main(const fml::CommandLine& command_line) {
42 if (command_line.HasOption("help")) {
43 Switches::PrintHelp(std::cout);
44 return true;
45 }
46
47 Switches switches(command_line);
48 if (!switches.AreValid(std::cerr)) {
49 std::cerr << "Invalid flags specified." << std::endl;
50 Switches::PrintHelp(std::cerr);
51 return false;
52 }
53
54 auto source_file_mapping =
56 if (!source_file_mapping) {
57 std::cerr << "Could not open input file." << std::endl;
58 return false;
59 }
60
61 fb::SceneT scene;
62 bool success = false;
63 switch (switches.input_type) {
65 success = ParseGLTF(*source_file_mapping, scene);
66 break;
68 std::cerr << "Unknown input type." << std::endl;
69 return false;
70 }
71 if (!success) {
72 std::cerr << "Failed to parse input file." << std::endl;
73 return false;
74 }
75
76 flatbuffers::FlatBufferBuilder builder;
77 builder.Finish(fb::Scene::Pack(builder, &scene), fb::SceneIdentifier());
78
79 auto output_file_name = std::filesystem::absolute(
80 std::filesystem::current_path() / switches.output_file_name);
81 fml::NonOwnedMapping mapping(builder.GetCurrentBufferPointer(),
82 builder.GetSize());
84 compiler::Utf8FromPath(output_file_name).c_str(),
85 mapping)) {
86 std::cerr << "Could not write file to " << switches.output_file_name
87 << std::endl;
88 return false;
89 }
90
91 // Tools that consume the geometry data expect the access mode to be 0644.
92 if (!SetPermissiveAccess(output_file_name)) {
93 return false;
94 }
95
96 return true;
97}
98
99} // namespace importer
100} // namespace scene
101} // namespace impeller
102
103int main(int argc, char const* argv[]) {
106 ? EXIT_SUCCESS
107 : EXIT_FAILURE;
108}
bool HasOption(std::string_view name, size_t *index=nullptr) const
Definition: command_line.cc:40
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
Definition: mapping.cc:20
const uint8_t uint32_t uint32_t GError ** error
char ** argv
Definition: library.h:9
static void * Pack(const T &ctx, SkArenaAlloc *alloc)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
bool WriteAtomically(const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
Definition: file_posix.cc:191
void InstallCrashHandler()
Definition: backtrace.cc:126
CommandLine CommandLineFromPlatformOrArgcArgv(int argc, const char *const *argv)
Definition: command_line.h:242
std::string Utf8FromPath(const std::filesystem::path &path)
Converts a native format path to a utf8 string.
Definition: utilities.cc:30
bool Main(const fml::CommandLine &command_line)
Definition: scenec_main.cc:40
static bool SetPermissiveAccess(const std::filesystem::path &p)
Definition: scenec_main.cc:26
bool ParseGLTF(const fml::Mapping &source_mapping, fb::SceneT &out_scene)
int main(int argc, char const *argv[])
Definition: scenec_main.cc:103
std::shared_ptr< fml::UniqueFD > working_directory
Definition: switches.h:20
static void PrintHelp(std::ostream &stream)
Definition: switches.cc:24
bool AreValid(std::ostream &explain) const
Definition: switches.cc:67