# Nine Patch Layer Nine patch layer is a concept to reduce the memory usage. Nine patch divides one image into nine areas and store it separately. For example, the shadow of the window is only meaningful on the edge and the corner of the window while the middle area is useless. In such case, having whole rectangle area is a waste of memory. Instead, we divide it into 4 corners, 4 edges and 1 middle rectangle area, and then drop the middle area. This is more memory saving. 4 + 4 + 1 is 9, so nine patch (probably?) ## In CC [NinePatchLayer](https://source.chromium.org/chromium/chromium/src/+/main:cc/layers/nine_patch_layer.h;l=18;drc=3f7a9d89de4c434583d520384b01ce87178ce888) is one of the layer that supports nine patch layer. [NinePatchGenerator](https://source.chromium.org/chromium/chromium/src/+/main:cc/layers/nine_patch_generator.h;l=34;drc=e3e2d25a2b0282de392fe655dcdbb59c7ce0d41f) is a helper class to generate the nine patch layer described above. The following is the image on the nine patch space. ```cpp= // Layer space layout // // -------------------------------- // | : : | // | J C | // | : : | // | ------------------ | // | | : | | // |~~~I~~| ------------ | | // | | | | | | // | | | | | | // |~~~A~~|~~| |~~|~B~~~~| // | | | | | | // | L ------------ | | // | | : | | // | ---K-------------- | // | D | // | : | // | : | // -------------------------------- // // Bitmap space layout // // ~~~~~~~~~~ W ~~~~~~~~~~ // : : | // : Y | // : : | // :~~X~~------------ | // : | : | // : | : | // H | Q | // : | : | // : ~~~~~P~~~~~ | // : | // : | // : | // ------------------------ // // |image_bounds| = (W, H) // |image_aperture| = (X, Y, P, Q) // |border| = (A, C, A + B, C + D) // |occlusion_rectangle| = (I, J, K, L) // |fill_center| indicates whether to draw the center quad or not. ``` ## Too busy day... maybe next time bye bye