| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Code generator for Ozone platform list. | 6 """Code generator for Ozone platform list. |
| 7 | 7 |
| 8 This script takes as arguments a list of platform names and generates a C++ | 8 This script takes as arguments a list of platform names and generates a C++ |
| 9 source file containing a list of those platforms. Each list entry contains the | 9 source file containing a list of those platforms. Each list entry contains the |
| 10 name and a function pointer to the initializer for that platform. | 10 name and a function pointer to the initializer for that platform. |
| 11 | 11 |
| 12 Example Output: ./generate_ozone_platform_list.py --default wayland dri wayland | 12 Example Output: ./generate_ozone_platform_list.py --default wayland dri wayland |
| 13 | 13 |
| 14 #include "ui/ozone/ozone_platform_list.h" | 14 #include "ui/ozone/ozone_platform_list.h" |
| 15 | 15 |
| 16 namespace ui { | 16 namespace ui { |
| 17 | 17 |
| 18 OzonePlatform* CreateOzonePlatformDri(); | 18 OzonePlatform* CreateOzonePlatformDriForUI(); |
| 19 OzonePlatform* CreateOzonePlatformWayland(); | 19 OzonePlatform* CreateOzonePlatformDriForGPU(); |
| 20 OzonePlatform* CreateOzonePlatformWaylandForUI(); |
| 21 OzonePlatform* CreateOzonePlatformWaylandForGPU(); |
| 20 | 22 |
| 21 const OzonePlatformListEntry kOzonePlatforms[] = { | 23 const OzonePlatformListEntry kOzonePlatforms[] = { |
| 22 { "wayland", &CreateOzonePlatformWayland }, | 24 { "wayland", |
| 23 { "dri", &CreateOzonePlatformDri }, | 25 &CreateOzonePlatformWaylandForUI, |
| 26 &CreateOzonePlatformWaylandForGPU }, |
| 27 { "dri", |
| 28 &CreateOzonePlatformDriForUI, |
| 29 &CreateOzonePlatformDriForGPU }, |
| 24 }; | 30 }; |
| 25 | 31 |
| 26 const int kOzonePlatformCount = 2; | 32 const int kOzonePlatformCount = 2; |
| 27 | 33 |
| 28 } // namespace ui | 34 } // namespace ui |
| 29 """ | 35 """ |
| 30 | 36 |
| 31 import optparse | 37 import optparse |
| 32 import os | 38 import os |
| 33 import collections | 39 import collections |
| (...skipping 15 matching lines...) Expand all Loading... |
| 49 """Generate static array containing a list of ozone platforms.""" | 55 """Generate static array containing a list of ozone platforms.""" |
| 50 | 56 |
| 51 out.write('#include "ui/ozone/ozone_platform_list.h"\n') | 57 out.write('#include "ui/ozone/ozone_platform_list.h"\n') |
| 52 out.write('\n') | 58 out.write('\n') |
| 53 | 59 |
| 54 out.write('namespace ui {\n') | 60 out.write('namespace ui {\n') |
| 55 out.write('\n') | 61 out.write('\n') |
| 56 | 62 |
| 57 # Prototypes for platform initializers. | 63 # Prototypes for platform initializers. |
| 58 for platform in platforms: | 64 for platform in platforms: |
| 59 out.write('OzonePlatform* %s();\n' % GetConstructorName(platform)) | 65 ctor = GetConstructorName(platform) |
| 66 out.write('OzonePlatform* %sForUI();\nOzonePlatform* %sForGPU();\n' % \ |
| 67 (ctor, ctor)) |
| 60 out.write('\n') | 68 out.write('\n') |
| 61 | 69 |
| 62 # List of platform names and initializers. | 70 # List of platform names and initializers. |
| 63 out.write('const OzonePlatformListEntry kOzonePlatforms[] = {\n') | 71 out.write('const OzonePlatformListEntry kOzonePlatforms[] = {\n') |
| 64 for platform in platforms: | 72 for platform in platforms: |
| 65 out.write(' { "%s", &%s },\n' % (platform, GetConstructorName(platform))) | 73 ctor = GetConstructorName(platform) |
| 74 out.write(' { "%s", &%sForUI, &%sForGPU },\n' % \ |
| 75 (platform, ctor, ctor)) |
| 66 out.write('};\n') | 76 out.write('};\n') |
| 67 out.write('\n') | 77 out.write('\n') |
| 68 | 78 |
| 69 out.write('const int kOzonePlatformCount = %d;\n' % len(platforms)) | 79 out.write('const int kOzonePlatformCount = %d;\n' % len(platforms)) |
| 70 out.write('\n') | 80 out.write('\n') |
| 71 | 81 |
| 72 out.write('} // namespace ui\n') | 82 out.write('} // namespace ui\n') |
| 73 | 83 |
| 74 | 84 |
| 75 def main(argv): | 85 def main(argv): |
| (...skipping 16 matching lines...) Expand all Loading... |
| 92 GeneratePlatformList(out, platforms) | 102 GeneratePlatformList(out, platforms) |
| 93 | 103 |
| 94 if options.output_file: | 104 if options.output_file: |
| 95 out.close() | 105 out.close() |
| 96 | 106 |
| 97 return 0 | 107 return 0 |
| 98 | 108 |
| 99 | 109 |
| 100 if __name__ == '__main__': | 110 if __name__ == '__main__': |
| 101 sys.exit(main(sys.argv[1:])) | 111 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |