forked from flutter/flutter
-
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.
Shader data can now be compiled into the binary.
There is no more need to figure out separate packaging of shader data.
- Loading branch information
1 parent
3ac38d8
commit 0b63e2c
Showing
6 changed files
with
244 additions
and
61 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
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
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,75 @@ | ||
# 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 sys | ||
|
||
import argparse | ||
import errno | ||
import os | ||
import struct | ||
|
||
def MakeDirectories(path): | ||
try: | ||
os.makedirs(path) | ||
except OSError as exc: | ||
if exc.errno == errno.EEXIST and os.path.isdir(path): | ||
pass | ||
else: | ||
raise | ||
|
||
# Dump the bytes of file into a C translation unit. | ||
# This can be used to embed the file contents into a binary. | ||
def Main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--symbol-name", | ||
type=str, required=True, | ||
help="The name of the symbol referencing the data.") | ||
parser.add_argument("--output-header", | ||
type=str, required=True, | ||
help="The header file containing the symbol reference.") | ||
parser.add_argument("--output-source", | ||
type=str, required=True, | ||
help="The source file containing the file bytes.") | ||
parser.add_argument("--source", | ||
type=str, required=True, | ||
help="The source file whose contents to embed in the output source file.") | ||
|
||
args = parser.parse_args() | ||
|
||
assert(os.path.exists(args.source)) | ||
|
||
output_header = os.path.abspath(args.output_header) | ||
output_source = os.path.abspath(args.output_source) | ||
|
||
MakeDirectories(os.path.dirname(output_header)) | ||
MakeDirectories(os.path.dirname(output_source)) | ||
|
||
with open(args.source, "rb") as source, open(output_source, "w") as output: | ||
data_len = 0 | ||
output.write(f"const unsigned char impeller_{args.symbol_name}_data[] =\n") | ||
output.write("{\n") | ||
while True: | ||
byte = source.read(1) | ||
if not byte: | ||
break | ||
data_len += 1 | ||
output.write(f"{ord(byte)},") | ||
output.write("};\n") | ||
output.write(f"const unsigned long impeller_{args.symbol_name}_length = {data_len};\n") | ||
|
||
with open(output_header, "w") as output: | ||
output.write("#pragma once\n") | ||
output.write("#ifdef __cplusplus\n") | ||
output.write("extern \"C\" {\n") | ||
output.write("#endif\n\n") | ||
|
||
output.write(f"extern unsigned char impeller_{args.symbol_name}_data[];\n") | ||
output.write(f"extern unsigned long impeller_{args.symbol_name}_length;\n\n") | ||
|
||
output.write("#ifdef __cplusplus\n") | ||
output.write("}\n") | ||
output.write("#endif\n") | ||
|
||
if __name__ == '__main__': | ||
Main() |