Commit da2f4d18 authored by Yi Xu's avatar Yi Xu Committed by Commit Bot

OffscreenCanvas: Don't copy previous content if canvas is fully repaint

In the previous CL,
https://chromium-review.googlesource.com/c/chromium/src/+/2063733, I
added mode change for Canvas, such that it discard the content of canvas
from the previous frame if canvas needs a full repaint in the current
frame. In this Cl, I added the mode change feature for OffScreenCanvas.

Bug: 1054666

Change-Id: I2b685641c40f2a31b50e04ee739f3ef26423297c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2088021
Commit-Queue: Yi Xu <yiyix@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748861}
parent 9165a15f
...@@ -380,7 +380,7 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin, ...@@ -380,7 +380,7 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin,
virtual void DisableAcceleration() {} virtual void DisableAcceleration() {}
virtual bool IsPaint2D() const { return false; } virtual bool IsPaint2D() const { return false; }
virtual void WillOverwriteCanvas() {} virtual void WillOverwriteCanvas() = 0;
private: private:
void RealizeSaves(); void RealizeSaves();
......
...@@ -350,6 +350,10 @@ bool OffscreenCanvasRenderingContext2D::IsAccelerated() const { ...@@ -350,6 +350,10 @@ bool OffscreenCanvasRenderingContext2D::IsAccelerated() const {
return IsPaintable() && GetCanvasResourceProvider()->IsAccelerated(); return IsPaintable() && GetCanvasResourceProvider()->IsAccelerated();
} }
void OffscreenCanvasRenderingContext2D::WillOverwriteCanvas() {
GetCanvasResourceProvider()->SkipQueuedDrawCommands();
}
String OffscreenCanvasRenderingContext2D::font() const { String OffscreenCanvasRenderingContext2D::font() const {
if (!GetState().HasRealizedFont()) if (!GetState().HasRealizedFont())
return kDefaultFont; return kDefaultFont;
......
...@@ -136,6 +136,7 @@ class MODULES_EXPORT OffscreenCanvasRenderingContext2D final ...@@ -136,6 +136,7 @@ class MODULES_EXPORT OffscreenCanvasRenderingContext2D final
size_t row_bytes, size_t row_bytes,
int x, int x,
int y) override; int y) override;
void WillOverwriteCanvas() override;
private: private:
bool have_recorded_draw_commands_; bool have_recorded_draw_commands_;
......
<!doctype html>
<html> <html>
<head>
</head>
<body> <body>
<canvas id="c" width=800 height=1000></canvas> <canvas id="can" width="100" height="100"></canvas>
<script> <script>
var canvas = document.getElementById('c');
var ctx = canvas.getContext("2d"); var outputCanvas = document.getElementById("can");
ctx.fillRect(50, 50, 50, 50); var outputContext = outputCanvas.getContext("2d");
ctx.fillRect(5, 5, 50, 50); outputContext.fillRect(0, 0, 15, 15);
outputContext.fillRect(50, 90, 50, 10);
</script> </script>
</body> </body>
</html> </html>
\ No newline at end of file
<html> <html>
<body> <body>
<canvas id="c" width=800 height=1000></canvas> <canvas id="c" width=100 height=100></canvas>
<script> <script>
// Test Canvas content shows up correctly after a full repaint. // Test Canvas content shows up correctly after a full repaint.
var canvas = document.getElementById('c'); var c2 = document.getElementById("c");
let ctx = canvas.getContext("2d"); var ctx = c2.getContext('2d');
function step() { // Since it checks if content retaining |mode_| changes from frame to frame,
// multiple calls to rAF are used to assure the craetion of new frame.
ctx.fillRect(5, 5, 50, 50);
ctx.clearRect(0, 0, 800, 1000);
window.requestAnimationFrame( dt=> {
ctx.fillRect(50, 50, 50, 50); ctx.fillRect(50, 50, 50, 50);
} ctx.clearRect(50, 50, 50, 40);
window.requestAnimationFrame(dt => {
ctx.fillRect(0, 0, 15, 15);
});
});
ctx.clearRect(0, 0, 800, 1000);
ctx.fillRect(5, 5, 50, 50);
window.requestAnimationFrame(step);
</script> </script>
</body> </body>
</html> </html>
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
var canvas = document.getElementById('c'); var canvas = document.getElementById('c');
let ctx = canvas.getContext("2d"); let ctx = canvas.getContext("2d");
// Since it checks if content retaining |mode_| changes from frame to frame,
// multiple calls to rAF are used to assure the craetion of new frame.
ctx.fillRect(0, 0, 50, 50); ctx.fillRect(0, 0, 50, 50);
window.requestAnimationFrame(dt => { window.requestAnimationFrame(dt => {
ctx.clearRect(0, 0, 40, 50); ctx.clearRect(0, 0, 40, 50);
......
<!doctype html>
<html>
<head>
</head>
<body>
<canvas id="can" width="100" height="100"></canvas>
<script>
var outputCanvas = document.getElementById("can");
var outputContext = outputCanvas.getContext("2d");
outputContext.fillRect(0, 0, 15, 15);
outputContext.fillRect(50, 90, 50, 10);
</script>
</body>
</html>
\ No newline at end of file
<!doctype html>
<html>
<head>
<title>Test ClearRect works properly if called during the first frame.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<canvas id="c" width=100 height=100></canvas>
<script>
var c2 = document.getElementById("c");
var offscreen_canvas = c2.transferControlToOffscreen();
var ctx_o = offscreen_canvas.getContext('2d');
// Since it checks if content retaining |mode_| changes from frame to frame,
// multiple calls to rAF are used to assure the craetion of new frame.
ctx_o.fillRect(5, 5, 50, 50);
ctx_o.clearRect(0, 0, 800, 1000);
window.requestAnimationFrame( dt=> {
ctx_o.fillRect(50, 50, 50, 50);
ctx_o.clearRect(50, 50, 50, 40);
window.requestAnimationFrame(dt => {
ctx_o.fillRect(0, 0, 15, 15);
window.requestAnimationFrame(dt => {
testRunner.notifyDone();
});
});
});
if (window.testRunner) {
testRunner.waitUntilDone();
}
</script>
</body>
</html>
<!doctype html>
<html>
<head>
</head>
<body>
<canvas id="can" width="100" height="100"></canvas>
<script>
var outputCanvas = document.getElementById("can");
var outputContext = outputCanvas.getContext("2d");
outputContext.fillRect(0, 0, 15, 15);
outputContext.fillRect(50, 90, 50, 10);
</script>
</body>
</html>
\ No newline at end of file
<!doctype html>
<html>
<head>
<title>Test ClearRect works properly if it doesn't clear the full canvas.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<canvas id="c" width=100 height=100></canvas>
<script>
var c2 = document.getElementById("c");
var offscreen_canvas = c2.transferControlToOffscreen();
var ctx_o = offscreen_canvas.getContext('2d');
// Since it checks if content retaining |mode_| changes from frame to frame,
// multiple calls to rAF are used to assure the craetion of new frame.
ctx_o.fillRect(50, 50, 50, 50);
ctx_o.clearRect(0, 0, 100, 90);
window.requestAnimationFrame(dt => {
ctx_o.fillRect(0, 0, 15, 15);
window.requestAnimationFrame(dt => {
testRunner.notifyDone();
});
});
if (window.testRunner) {
testRunner.waitUntilDone();
}
</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