Patent ID: 8842131

Claim:
A method, comprising: traversing a user interface tree of widgets corresponding to widgets requiring clipping that are present in a scene to be rendered; for each encountered widget, performing layer allocation operations comprising: selecting a current, previous, or next layer to which to allocate the widget; determining whether the selected layer can accommodate the widget; based on a determination that the selected layer cannot accommodate the widget, allocating a bit from a stencil buffer to the selected layer and incrementing a value of the selected layer to account for the widget being allocated to the selected layer; based on a determination that the selected layer can accommodate the widget, incrementing the value of the selected layer to account for the widget being allocated to the selected layer; generating a stencil test mask formed as a combination of the values of layers previous to a current layer; writing the stencil test mask to a stencil buffer; and repeating the layer allocation operations for each remaining widget, generating, by a processor, a reference layer comprising a logical OR of the current value of all layers; generating a draw test mask comprising bits of the stencil buffer that are allocated to all layers; applying the draw test mask to the stencil buffer; passing contents of the stencil buffer to a frame buffer for drawing a pixel; generating a write mask that contains bits allocated to the current laver, the write mask preventing writing to other layers; and applying both the stencil test mask and the draw test mask to the reference layer and the current value of the stencil buffer before the pixel is drawn.