Skip to content

Commit

Permalink
Fix ImageBitmapRenderingContext interaction with software compositor.
Browse files Browse the repository at this point in the history
Before this CL, there was an early exit condition that prevented
texture-backed resources from being presented to the software compositor
even when the texture backing is swiftshader. This meant that in some
cases, ImageBitmaps that were created by webGL contexts would fail to
render.  Once the early exit removed, there were other bugs due to the
fact that bitmaps were not being converted to N32 format before being
dispatched to the software compositor.  This could cause several types
of rendering artifacts, including leaking bitmap data between contexts.

BUG=1283434

Change-Id: I6f353bc6301b79d7a4124445c85956125135f539
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3387268
Reviewed-by: Juanmi Huertas <juanmihd@chromium.org>
Commit-Queue: Justin Novosad <junov@chromium.org>
Cr-Commit-Position: refs/heads/main@{#959192}
  • Loading branch information
junov authored and Chromium LUCI CQ committed Jan 14, 2022
1 parent 07743b7 commit eb967bf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ bool ImageLayerBridge::PrepareTransferableResource(
has_presented_since_last_set_image_ = true;

const bool gpu_compositing = SharedGpuContext::IsGpuCompositingEnabled();
const bool gpu_image = image_->IsTextureBacked();

// Expect software images for software compositing.
if (!gpu_compositing && gpu_image)
return false;

const ImageOrientation origin = image_->IsOriginTopLeft()
? ImageOrientationEnum::kOriginTopLeft
Expand Down Expand Up @@ -211,14 +206,17 @@ bool ImageLayerBridge::PrepareTransferableResource(
return false;

const gfx::Size size(image_->width(), image_->height());
viz::ResourceFormat resource_format = viz::RGBA_8888;
if (sk_image->colorType() == SkColorType::kRGBA_F16_SkColorType)
resource_format = viz::RGBA_F16;

// Always convert to N32 format. This is a constraint of the software
// compositor.
constexpr SkColorType dst_color_type = kN32_SkColorType;
viz::ResourceFormat resource_format =
viz::SkColorTypeToResourceFormat(dst_color_type);
RegisteredBitmap registered =
CreateOrRecycleBitmap(size, resource_format, bitmap_registrar);

SkImageInfo dst_info =
SkImageInfo::Make(size.width(), size.height(), sk_image->colorType(),
SkImageInfo::Make(size.width(), size.height(), dst_color_type,
kPremul_SkAlphaType, sk_image->refColorSpace());
void* pixels = registered.bitmap->memory();

Expand Down Expand Up @@ -247,8 +245,8 @@ ImageLayerBridge::RegisteredBitmap ImageLayerBridge::CreateOrRecycleBitmap(
recycled_bitmaps_.begin(), recycled_bitmaps_.end(),
[&size, &format](const RegisteredBitmap& registered) {
unsigned src_bytes_per_pixel =
(registered.bitmap->format() == viz::RGBA_8888) ? 4 : 8;
unsigned target_bytes_per_pixel = (format == viz::RGBA_8888) ? 4 : 8;
viz::BitsPerPixel(registered.bitmap->format()) / 8;
unsigned target_bytes_per_pixel = viz::BitsPerPixel(format) / 8;
return (registered.bitmap->size().GetArea() * src_bytes_per_pixel !=
size.GetArea() * target_bytes_per_pixel);
});
Expand Down
11 changes: 11 additions & 0 deletions third_party/blink/web_tests/fast/canvas/bug1283434-expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

<!doctype html>
<html>
<head>
</head>
<body>
<p>The two squares below should be filled in blue.</p>
<canvas id="c" width="100" height="100" style="background-color: #00f;"></canvas>
<canvas id="c2" width="100" height="100" style="background-color: #00f;"></canvas>
</body>
</html>
28 changes: 28 additions & 0 deletions third_party/blink/web_tests/fast/canvas/bug1283434.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

<!doctype html>
<html>
<head>
</head>
<body>
<p>The two squares below should be filled in blue.</p>
<canvas id="c" width="100" height="100" style="background-color: red;"></canvas>
<canvas id="c2" width="100" height="100" style="background-color: red;"></canvas>
<script>
const canvas = document.getElementById('c');
const canvas2 = document.getElementById('c2');
const renderer = canvas.getContext('bitmaprenderer');
const renderer2 = canvas2.getContext('2d');

const temp_canvas = new OffscreenCanvas(640, 480);
const gl = temp_canvas.getContext('webgl');

gl.clearColor(0.0, 0.0, 1.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);

const bitmap = temp_canvas.transferToImageBitmap();

renderer2.drawImage(bitmap, 0, 0);
renderer.transferFromImageBitmap(bitmap);
</script>
</body>
</html>

0 comments on commit eb967bf

Please sign in to comment.