Commit b9a32610 authored by Philip Rogers's avatar Philip Rogers Committed by Commit Bot

[PaintTouchActionRects] Paint hit test rects when acceleration skips bg

When a canvas is accelerated, the background is sometimes painted into
the content layer (see ContentLayerSupportsDirectBackgroundComposition).
When this occurs, we can skip painting the background but still need to
paint the hit test rects.

Bug: 903480
Change-Id: Iec5d564ffed9611011d78adc381c9d7d7153e960
Reviewed-on: https://chromium-review.googlesource.com/c/1329854Reviewed-by: default avatarXianda Sun <sunxd@chromium.org>
Commit-Queue: Philip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607238}
parent d1908438
......@@ -54,7 +54,10 @@
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/platform/geometry/int_point.h"
#include "third_party/blink/renderer/platform/geometry/int_rect.h"
#include "third_party/blink/renderer/platform/graphics/gpu/shared_gpu_context.h"
#include "third_party/blink/renderer/platform/graphics/graphics_layer.h"
#include "third_party/blink/renderer/platform/graphics/test/fake_gles2_interface.h"
#include "third_party/blink/renderer/platform/graphics/test/fake_web_graphics_context_3d_provider.h"
#include "third_party/blink/renderer/platform/graphics/touch_action.h"
#include "third_party/blink/renderer/platform/testing/histogram_tester.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
......@@ -1841,4 +1844,59 @@ TEST_P(NonCompositedMainThreadScrollingReasonTest,
ASSERT_TRUE(scrollable_area2->UsesCompositedScrolling());
}
class ScrollingCoordinatorTestWithAcceleratedContext
: public ScrollingCoordinatorTest {
public:
ScrollingCoordinatorTestWithAcceleratedContext()
: ScrollingCoordinatorTest() {}
protected:
void SetUp() override {
auto factory = [](FakeGLES2Interface* gl, bool* gpu_compositing_disabled)
-> std::unique_ptr<WebGraphicsContext3DProvider> {
*gpu_compositing_disabled = false;
gl->SetIsContextLost(false);
return std::make_unique<FakeWebGraphicsContext3DProvider>(gl);
};
SharedGpuContext::SetContextProviderFactoryForTesting(
WTF::BindRepeating(factory, WTF::Unretained(&gl_)));
ScrollingCoordinatorTest::SetUp();
}
void TearDown() override {
SharedGpuContext::ResetForTesting();
ScrollingCoordinatorTest::TearDown();
}
private:
FakeGLES2Interface gl_;
};
INSTANTIATE_TEST_CASE_P(All,
ScrollingCoordinatorTestWithAcceleratedContext,
::testing::Bool());
TEST_P(ScrollingCoordinatorTestWithAcceleratedContext, CanvasTouchActionRects) {
LoadHTML(R"HTML(
<canvas id="canvas" style="touch-action: none; will-change: transform;">
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
canvas.width = 400;
canvas.height = 400;
ctx.fillStyle = 'lightgrey';
ctx.fillRect(0, 0, 400, 400);
</script>
)HTML");
ForceFullCompositingUpdate();
Element* canvas = GetFrame()->GetDocument()->getElementById("canvas");
auto* canvas_box = ToLayoutBox(canvas->GetLayoutObject());
auto* mapping = canvas_box->Layer()->GetCompositedLayerMapping();
cc::Layer* cc_layer = mapping->MainGraphicsLayer()->CcLayer();
cc::Region region = cc_layer->touch_action_region().GetRegionForTouchAction(
TouchAction::kTouchActionNone);
EXPECT_EQ(region.bounds(), gfx::Rect(0, 0, 400, 400));
}
} // namespace blink
......@@ -120,8 +120,16 @@ void ReplacedPainter::Paint(const PaintInfo& paint_info) {
kPaintsIntoOwnBacking &&
layout_replaced_.Layer()
->GetCompositedLayerMapping()
->DrawsBackgroundOntoContentLayer())
->DrawsBackgroundOntoContentLayer()) {
// If the background paints into the content layer, we can skip painting
// the background but still need to paint the touch action rects.
if (RuntimeEnabledFeatures::PaintTouchActionRectsEnabled()) {
BoxPainter(layout_replaced_)
.RecordHitTestData(local_paint_info, paint_offset, border_rect,
layout_replaced_);
}
return;
}
BoxPainter(layout_replaced_)
.PaintBoxDecorationBackground(local_paint_info, paint_offset);
......
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