CABackdropLayer

From iPhone Development Wiki

CABackdropLayer is a subclass of CALayer that clones the content behind it as its own contents. It's useful for applying effects that only apply to some part of the screen, which might be made up of any number of layers behind it.

Gathering Statistics With CABackdropLayer

CABackdropLayer supports gathering various statistics about the contents it clones. Several "statistics types" might be supported, although, currently, it seems (from reversing this feature), that only one type is supported: "type1".

This information was gathered by inspecting the -[CABackdropLayer statisticsValues] method. More info is in the screenshot.

Screenshot from IDA of the -statisticsValues method

Type1 statistics

type1 statistics gathers:

  • time
  • color average (RGB values).
  • luminance standard deviation

How to enable example (this is pseudo code at best):

// 1) create a window from a subclass that has its layerClass defined as CABackdropLayer.
MyWindow *w = [[MyWindow alloc] initWithFrame:f];
w.hidden = NO;

// 2) Set the type
w.layer.statisticsType = kCABackdropStatisticsType1;

// optional: set the interval (in seconds), by default it is 0.25.
w.layer.statisticsInterval = 5;

// finally just call -statisticsValues. An NSDictionary is returned.
[w.layer statisticsValues]
@{"type":"type1","time":46141.687733625,"blueAverage":0.1781699346405229,"greenAverage":0.1045315904139434,"luminanceStandardDeviation":0.1162156672244852,"redAverage":0.06554829339143065}

Exported Keys and Types

Add this to your `class-dump`-ed CABackdropLayer.h header file (should be used instead of plain strings).

/* Statistics Types */
extern NSString *kCABackdropStatisticsType1;
extern NSString *kCABackdropStatisticsNone;

/* Statisctics Type1 keys */
extern NSString *kCABackdropStatisticsRedAverage;
extern NSString *kCABackdropStatisticsGreenAverage;
extern NSString *kCABackdropStatisticsBlueAverage;
extern NSString *kCABackdropStatisticsLuminanceStandardDeviation;
extern NSString *kCABackdropStatisticsType;
extern NSString *kCABackdropStatisticsTime;