The cc/ directory is currently rather large. It has 384 C++ files, 176 of which are headers containing a little over 90k lines. cc/test/ has another 70 source files with ~5k lines of code. It's very convenient to have all of the compositor source in one directory, but I'm worried we are pushing the bounds of understandability. Or possibly we crossed over it long ago and we just didn't notice. Is it time to break this up?
I did a bit of analysis on C++ code in the rest of the Chromium repository (not stuff in third_party). cc/ has the most source files in any single directory, just behind chrome/browser/extensions/ which has 432. Just behind cc/ there's net/base/ which is 351 and base/ with 309. In terms of headers, cc/ is in the lead followed by chrome/browser/extensions (165), net/base (146), base/ (132) and content/public/browser (129). Here are some histograms (that may be buggy, I just hacked this code up quickly):
[0 - 8] 793 (56.7%) .........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
[8 - 17] 254 (18.2%) (74.9%) ..............................................................................................................................................................................................................................................................
[17 - 28] 127 (9.1%) (84.0%) ...............................................................................................................................
[28 - 40] 73 (5.2%) (89.2%) .........................................................................
[40 - 54] 54 (3.9%) (93.1%) ......................................................
[54 - 70] 29 (2.1%) (95.1%) .............................
[70 - 89] 21 (1.5%) (96.6%) .....................
[89 - 110] 12 (0.9%) (97.5%) ............
[110 - 135] 15 (1.1%) (98.6%) ...............
[135 - 163] 7 (0.5%) (99.1%) .......
[163 - 196] 7 (0.5%) (99.6%) .......
[196 - 234] 2 (0.1%) (99.7%) ..
[234 - 277] 0 (0.0%) (99.7%)
[277 - 327] 1 (0.1%) (99.8%) .
[327 - 384] 3 (0.2%) (100.0%) ...
Headers
[0 - 3] 714 (51.1%) ..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
[3 - 7] 254 (18.2%) (69.2%) ..............................................................................................................................................................................................................................................................
[7 - 12] 157 (11.2%) (80.5%) .............................................................................................................................................................
[12 - 17] 81 (5.8%) (86.3%) .................................................................................
[17 - 24] 76 (5.4%) (91.7%) ............................................................................
[24 - 31] 40 (2.9%) (94.6%) ........................................
[31 - 39] 21 (1.5%) (96.1%) .....................
[39 - 49] 14 (1.0%) (97.1%) ..............
[49 - 60] 15 (1.1%) (98.1%) ...............
[60 - 72] 11 (0.8%) (98.9%) ...........
[72 - 87] 5 (0.4%) (99.3%) .....
[87 - 104] 5 (0.4%) (99.6%) .....
[104 - 123] 0 (0.0%) (99.6%)
[123 - 145] 2 (0.1%) (99.8%) ..
[145 - 170] 3 (0.2%) (100.0%) ...
cc/ is in the top bucket for both, of course, and it's relatively lonely.
I'm worried that the sheer number of files makes it harder to understand the compositor's code structure and organization and makes it harder to understand how it's supposed to be used as a library. It's also harder to understand and enforce the logical dependencies inside cc/. The downside of splitting things up would be it would be harder to find and edit files within the cc/ directory and moving files would be somewhat disruptive. On balance, I currently think it'd be better to break things up than to not, but I could definitely be convinced otherwise.
Here's a strawman directory structure that divides things based on topic to see what it would look like. I think this is an upper bound on the number of directories that would make sense. I could definitely see collapsing some of these together, but we probably don't want more. This is just a starting point for discussion and not at all set in stone:
cc/animation/ - *animation*, timing_function, transform_operations. 22 files
cc/base/ - common functionality with no dependencies on the rest of cc like thread, hash_pair, util, region, worker_pool, scoped_*. 27 files
cc/debug/ - support for heads_up_display, rendering_stats, devtools_instrumentation, debug colors, debug settings, frame_rate_counter, paint_time_counter. 17 files
cc/input/ - input_handler, top_controls_manager, page_scale_animation. 7 files
cc/layers/ - layer.h, *_layer.h, layer_impl.h, *_layer_impl.h and associated tests. 86 files
cc/scheduler/ - scheduler, scheduler_state_machine, time_sources, frame_rate_controller. 23 files
cc/quads/ - *_draw_quad.* and tests, and possibly the pass code as well. 24 files
cc/raster/ - rasterizing logic. all of our updaters, picture_pile_*, tiling managers, etc. 42 files
cc/renderer/ - renderer, direct_renderer, output_surface anything else that's not specific to GL vs software. 19 files
cc/renderer/gl - gl-specific rendering stuff. gl_renderer, shader, program, geometry_bindings, texture_copier, mailbox stuff. 17 files
cc/renderer/software - software-specific rendering stuff. software_renderer, _output_device, _frame_data. 7 files
cc/resources/ - resource, resource_pool, prioritized_resource(_manager)?, possibly priority_calculator, memory policy code. 32 files
cc/trees/ - stuff that deals with a layer tree. layer_tree_host(_impl|_common), tree_synchronizer, occlusion_tracker, proxies. 53 files
Here would be the allowed dependencies:
Everything - can depend on cc/base (and probably cc/debug)
cc/animation - depends on nothing else
cc/debug - depends on nothing else
cc/input - depends on layers, trees
cc/layers - depends on animation, trees, quads, raster, resources
cc/scheduler - depends on nothing else
cc/quads - depends on resources
cc/raster - depends on layers, quads, resources
cc/renderer - depends on quads
cc/resources - depends on nothing else
cc/trees - depends on everything else
I like that this produces several leaf nodes in the tree and nothing is too huge, although "layers" and "trees" are both somewhat unwieldy. I think we have a few cycles, and probably more than I'm thinking of here, but as long as it's controlled I think this is not the end of the world. After all, cc is a single component. I do think we want to maintain a few of these dependencies strictly, however. For instance, quads shouldn't depend on layers no matter what.
Not listed here is cc/test/, which will continue to contain test infrastructure, depend on everything else in cc/ and not be depended on by anything else in cc/
What do you think? Should we split things up at all or not? If we do, how much splitting should we do? The strawman would drop our average files per directory down to just under 30 which is definitely a big change.
- James