Commit b002f0c2 authored by Annie Sullivan's avatar Annie Sullivan Committed by Commit Bot

Add paint timing support for webgl2 canvas.

Bug: 1112857
Change-Id: I2c76e95ecb139d3359877e71c6f3713f4d9f3c37
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2348694Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Annie Sullivan <sullivan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797698}
parent 6bb25dc1
......@@ -814,7 +814,7 @@ void HTMLCanvasElement::Paint(GraphicsContext& context,
if (!context_ && !OffscreenCanvasFrame())
return;
if (HasResourceProvider() && !canvas_is_clear_)
if (!canvas_is_clear_)
PaintTiming::From(GetDocument()).MarkFirstContentfulPaint();
// If the canvas is gpu composited, it has another way of getting to screen
......
......@@ -9,6 +9,7 @@
#include "third_party/blink/renderer/core/layout/layout_html_canvas.h"
#include "third_party/blink/renderer/core/paint/box_painter.h"
#include "third_party/blink/renderer/core/paint/paint_info.h"
#include "third_party/blink/renderer/core/paint/paint_timing.h"
#include "third_party/blink/renderer/platform/geometry/layout_point.h"
#include "third_party/blink/renderer/platform/graphics/paint/drawing_recorder.h"
#include "third_party/blink/renderer/platform/graphics/paint/foreign_layer_display_item.h"
......@@ -44,6 +45,8 @@ void HTMLCanvasPainter::PaintReplaced(const PaintInfo& paint_info,
if (RuntimeEnabledFeatures::CompositeAfterPaintEnabled() &&
!flatten_composited_layers) {
if (auto* layer = canvas->ContentsCcLayer()) {
PaintTiming::From(layout_html_canvas_.GetDocument())
.MarkFirstContentfulPaint();
IntRect pixel_snapped_rect = PixelSnappedIntRect(paint_rect);
layer->SetBounds(gfx::Size(pixel_snapped_rect.Size()));
layer->SetIsDrawable(true);
......
<!DOCTYPE html>
<head>
<title>Performance Paint Timing Test: FCP due to canvas</title>
</head>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>
<canvas id="canvas" width="200" height="200"></canvas>
<script>
setup({"hide_test_state": true});
promise_test(async t => {
assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");
await new Promise(r => window.addEventListener('load', r));
await assertNoFirstContentfulPaint(t);
}, 'First contentful paint should not fire for canvas type none');
</script>
</body>
</html>
<!DOCTYPE html>
<head>
<title>Performance Paint Timing Test: FCP due to canvas</title>
</head>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<canvas id="canvas" width="200" height="200"></canvas>
<script>
setup({ "hide_test_state": true });
async_test(function (t) {
assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");
const canvas = document.getElementById("canvas");
const context = canvas.getContext("webgl2");
if (!context) {
assert_implements_optional(context, "WebGL 2 Canvas isn't supported.")
}
context.clearColor(0.3, 0.3, 0.3, 1);
context.clear(context.COLOR_BUFFER_BIT);
function testPaintEntries() {
const bufferedEntries = performance.getEntriesByType('paint');
if (bufferedEntries.length < 2) {
t.step_timeout(function () {
testPaintEntries();
}, 20);
return;
}
t.step(function () {
assert_equals(bufferedEntries.length, 2, "There should be two paint timing instances.");
assert_equals(bufferedEntries[0].entryType, "paint");
assert_equals(bufferedEntries[0].name, "first-paint");
assert_equals(bufferedEntries[1].entryType, "paint");
assert_equals(bufferedEntries[1].name, "first-contentful-paint");
t.done();
});
};
t.step(function () {
testPaintEntries();
});
}, "First contentful paint fires due to webgl2 canvas render.");
</script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment