Created attachment 516707[details][diff][review]
part 1: fix context options
This first patch is easy: it fixes the WebGLContext options according to the spec, that is:
* rename antialiasHint to antialias, default to true (the spec does not mandate antialiasing being actually happening)
* add preserveDrawingBuffer
This patch also does this:
- if (!GetBoolFromPropertyBag(aOptions, "stencil", &newOpts.stencil))
- newOpts.stencil = false;
+ GetBoolFromPropertyBag(aOptions, "stencil", &newOpts.stencil);
This is from Vlad's patch. The point is that GetBoolFromPropertyBag already does nothing to the output value if it fails.

Created attachment 531354[details][diff][review]
Part 3: implement ForceClearFramebufferWithDefaultValues from the existing renderbuffer init code
We will need this function to actually implement the buffer clearing. Vlad's patch was using GLContext::ClearSafely() and making it a little more powerful, but still not powerful enough. Meanwhile we already had the needed code in WebGL for renderbuffer initialization. So, this patch takes this reusable code into a self-contained function.

Created attachment 531451[details][diff][review]
Part 4: implement the clear semantics
This is where we actually implement the clear semantics, i.e. the notion that after the WebGL back buffer has been presented to the compositor, if the preserveDrawingBuffer context option is false, before the next WebGL draw/clear/readPixels call, the back buffer must be cleared with the default values (color=black, depth=1.0, etc).

Comment on attachment 531451[details][diff][review]
Part 4: implement the clear semantics
Benoit tells me that there's going to have to be a new version of this patch due to test failures, so I'll look at this patch later.

Created attachment 533991[details][diff][review]
Part 5: fix buffer-preserve-test.html so it works in the mochitest
This test relies on the canvas getting composited. It worked fine standalone, but when included as a small frame in the test runner page, the canvas fell off the visible part and therefore wasn't getting composited. Fixing this by putting the canvas at the top of the page. Going to upstream this.