Skip to content

Commit

Permalink
Revert "[Reland] Use direct compositing for canvases rendered on the …
Browse files Browse the repository at this point in the history
…CPU"

This reverts commit c8d899d.

Reason for revert: Inspect overlay not working on mac

Original change's description:
> [Reland] Use direct compositing for canvases rendered on the CPU
>
> Before this CL, we already had the plumbing for presenting CPU-rendered
> canvases via GpuMemoryBuffer for direct compositing.  That code path was
> originally implemented to support LowLatency mode. With this change, we
> exercise the GpuMemoryBuffer code path for "regular" latency canvases.
> This accelerates compositing, especially for pages that have many
> canvases.
>
> With this change, MotionMark Images test runs significantly faster on
> MacOS with angle/metal enabled.
>
> Reland of original CL: https://chromium-review.googlesource.com/c/chromium/src/+/4081383
>
> Bug: 1363627
> Change-Id: I9380c7f722954af934a657a71c36c37122731f45
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4091749
> Reviewed-by: Juanmi Huertas <juanmihd@chromium.org>
> Commit-Queue: Justin Novosad <junov@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1083400}

Bug: 1363627, 1402668
Change-Id: Ibcba46d58ec06c50ae7b3fe7bddd84791ab14535
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4157253
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Commit-Queue: Justin Novosad <junov@chromium.org>
Cr-Commit-Position: refs/branch-heads/5481@{#275}
Cr-Branched-From: 130f3e4-refs/heads/main@{#1084008}
  • Loading branch information
junov authored and Chromium LUCI CQ committed Jan 13, 2023
1 parent 6bae86c commit 5e44208
Show file tree
Hide file tree
Showing 145 changed files with 59 additions and 351 deletions.
Expand Up @@ -75,16 +75,15 @@ TEST_F(HTMLCanvasPainterTest, Canvas2DLayerAppearsInLayerTree) {
std::unique_ptr<Canvas2DLayerBridge> bridge = MakeCanvas2DLayerBridge(size);
element->SetResourceProviderForTesting(nullptr, std::move(bridge), size);
ASSERT_EQ(context, element->RenderingContext());
ASSERT_TRUE(context->IsComposited());
ASSERT_TRUE(element->IsAccelerated());

// Force the page to paint.
element->PreFinalizeFrame();
context->FinalizeFrame();
element->PostFinalizeFrame();
UpdateAllLifecyclePhasesForTest();

ASSERT_TRUE(context->IsComposited());
ASSERT_TRUE(element->IsAccelerated());

// Fetch the layer associated with the <canvas>, and check that it was
// correctly configured in the layer tree.
const cc::Layer* layer = context->CcLayer();
Expand Down
Expand Up @@ -189,10 +189,7 @@ bool CanvasRenderingContext2D::IsOriginTopLeft() const {
}

bool CanvasRenderingContext2D::IsComposited() const {
if (Canvas2DLayerBridge* layer_bridge = canvas()->GetCanvas2DLayerBridge()) {
return layer_bridge->IsComposited();
}
return false;
return IsAccelerated();
}

void CanvasRenderingContext2D::Stop() {
Expand Down
Expand Up @@ -152,25 +152,6 @@ bool Canvas2DLayerBridge::IsAccelerated() const {
return ShouldAccelerate();
}

bool Canvas2DLayerBridge::IsComposited() const {
if (IsHibernating()) {
return false;
}

if (UNLIKELY(!resource_host_)) {
return false;
}

CanvasResourceProvider* resource_provider =
resource_host_->ResourceProvider();
if (UNLIKELY(!resource_provider)) {
return false;
}

return resource_provider->SupportsDirectCompositing() &&
!resource_host_->LowLatencyEnabled();
}

static void HibernateWrapper(base::WeakPtr<Canvas2DLayerBridge> bridge,
base::TimeTicks /*idleDeadline*/) {
if (bridge) {
Expand Down Expand Up @@ -287,13 +268,14 @@ CanvasResourceProvider* Canvas2DLayerBridge::GetOrCreateResourceProvider() {

if (resource_provider && resource_provider->IsValid()) {
#if DCHECK_IS_ON()
// If resource provider is composited, a layer should already exist.
// If resource provider is accelerated, a layer should already exist.
// unless this is a canvas in low latency mode.
// If this DCHECK fails, it probably means that
// CanvasRenderingContextHost::GetOrCreateCanvasResourceProvider() was
// called on a 2D context before this function.
if (IsComposited()) {
DCHECK(!!layer_);
if (IsAccelerated()) {
DCHECK(!!layer_ ||
(resource_host_ && resource_host_->LowLatencyEnabled()));
}
#endif
return resource_provider;
Expand Down Expand Up @@ -328,7 +310,7 @@ CanvasResourceProvider* Canvas2DLayerBridge::GetOrCreateResourceProvider() {
// TODO crbug/1090081: Check possibility to move DidDraw inside Clear.
DidDraw();

if (IsComposited() && !layer_) {
if (IsAccelerated() && !layer_) {
layer_ = cc::TextureLayer::CreateForMailbox(this);
layer_->SetIsDrawable(true);
layer_->SetHitTestable(true);
Expand All @@ -338,7 +320,6 @@ CanvasResourceProvider* Canvas2DLayerBridge::GetOrCreateResourceProvider() {
cc::PaintFlags::FilterQuality::kNone);
layer_->SetHDRConfiguration(resource_host_->GetHDRMode(),
resource_host_->GetHDRMetadata());
layer_->SetFlipped(!resource_provider->IsOriginTopLeft());
}
// After the page becomes visible and successfully restored the canvas
// resource provider, set |lose_context_in_background_| to false.
Expand Down Expand Up @@ -772,7 +753,7 @@ void Canvas2DLayerBridge::FinalizeFrame(bool printing) {
constexpr unsigned kMaxCanvasAnimationBacklog = 2;
if (frames_since_last_commit_ >=
static_cast<int>(kMaxCanvasAnimationBacklog)) {
if (IsComposited() && !rate_limiter_) {
if (IsAccelerated() && !rate_limiter_) {
rate_limiter_ = std::make_unique<SharedContextRateLimiter>(
kMaxCanvasAnimationBacklog);
}
Expand All @@ -784,7 +765,7 @@ void Canvas2DLayerBridge::FinalizeFrame(bool printing) {
}

void Canvas2DLayerBridge::DoPaintInvalidation(const gfx::Rect& dirty_rect) {
if (layer_ && IsComposited()) {
if (layer_ && raster_mode_ == RasterMode::kGPU) {
layer_->SetNeedsDisplayRect(dirty_rect);
}
}
Expand Down
Expand Up @@ -95,8 +95,6 @@ class PLATFORM_EXPORT Canvas2DLayerBridge : public cc::TextureLayerClient {
virtual void DidRestoreCanvasMatrixClipStack(cc::PaintCanvas*) {}
virtual bool IsAccelerated() const;

bool IsComposited() const;

// This may recreate CanvasResourceProvider
cc::PaintCanvas* GetPaintCanvas();
bool IsValid();
Expand Down
Expand Up @@ -1019,29 +1019,4 @@ TEST_F(Canvas2DLayerBridgeTest, NonDisplayedCanvasIsNotRateLimited) {
EXPECT_FALSE(bridge->HasRateLimiterForTesting());
}

TEST_F(Canvas2DLayerBridgeTest, SoftwareCanvasIsCompositedIfImageChromium) {
ScopedTestingPlatformSupport<GpuMemoryBufferTestPlatform> platform;
ScopedCanvas2dImageChromiumForTest canvas_2d_image_chromium(true);
const_cast<gpu::Capabilities&>(SharedGpuContext::ContextProviderWrapper()
->ContextProvider()
->GetCapabilities())
.gpu_memory_buffer_formats.Add(gfx::BufferFormat::BGRA_8888);
std::unique_ptr<Canvas2DLayerBridge> bridge =
MakeBridge(gfx::Size(300, 150), RasterMode::kCPU, kNonOpaque);
EXPECT_TRUE(bridge->IsValid());
DrawSomething(bridge.get());
EXPECT_FALSE(bridge->IsAccelerated());
EXPECT_TRUE(bridge->IsComposited());
}

TEST_F(Canvas2DLayerBridgeTest, SoftwareCanvasNotCompositedIfNotImageChromium) {
ScopedCanvas2dImageChromiumForTest canvas_2d_image_chromium(false);
std::unique_ptr<Canvas2DLayerBridge> bridge =
MakeBridge(gfx::Size(300, 150), RasterMode::kCPU, kNonOpaque);
EXPECT_TRUE(bridge->IsValid());
DrawSomething(bridge.get());
EXPECT_FALSE(bridge->IsAccelerated());
EXPECT_FALSE(bridge->IsComposited());
}

} // namespace blink
Expand Up @@ -705,10 +705,7 @@ void CanvasResourceRasterSharedImage::CopyRenderingResultsToGpuMemoryBuffer(
auto surface = SkSurface::MakeRasterDirect(CreateSkImageInfo(),
gpu_memory_buffer_->memory(0),
gpu_memory_buffer_->stride(0));

SkPixmap pixmap;
image->peekPixels(&pixmap);
surface->writePixels(pixmap, 0, 0);
surface->getCanvas()->drawImage(image, 0, 0);
auto* sii =
ContextProviderWrapper()->ContextProvider()->SharedImageInterface();
gpu_memory_buffer_->Unmap();
Expand Down
Expand Up @@ -12,7 +12,6 @@
<link rel="help" href="http://www.w3.org/TR/css3-images/#the-object-fit">
<link rel="help" href="http://www.w3.org/TR/css3-images/#the-object-position">
<link rel="match" href="object-fit-contain-png-001-ref.html">
<meta name=fuzzy content="maxDifference=0-20;totalPixels=0-2000">
<style type="text/css">
canvas {
border: 1px dashed gray;
Expand Down
Expand Up @@ -12,7 +12,6 @@
<link rel="help" href="http://www.w3.org/TR/css3-images/#the-object-fit">
<link rel="help" href="http://www.w3.org/TR/css3-images/#the-object-position">
<link rel="match" href="object-fit-contain-png-002-ref.html">
<meta name=fuzzy content="maxDifference=0-20;totalPixels=0-2000">
<style type="text/css">
canvas {
border: 1px dashed gray;
Expand Down
Expand Up @@ -12,7 +12,6 @@
<link rel="help" href="http://www.w3.org/TR/css3-images/#the-object-fit">
<link rel="help" href="http://www.w3.org/TR/css3-images/#the-object-position">
<link rel="match" href="object-fit-fill-png-001-ref.html">
<meta name=fuzzy content="maxDifference=0-20;totalPixels=0-3200">
<style type="text/css">
canvas {
border: 1px dashed gray;
Expand Down
Expand Up @@ -12,7 +12,6 @@
<link rel="help" href="http://www.w3.org/TR/css3-images/#the-object-fit">
<link rel="help" href="http://www.w3.org/TR/css3-images/#the-object-position">
<link rel="match" href="object-fit-fill-png-002-ref.html">
<meta name=fuzzy content="maxDifference=0-20;totalPixels=0-3200">
<style type="text/css">
canvas {
border: 1px dashed gray;
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.
Diff not rendered.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 5e44208

Please sign in to comment.