Commit 5de5acf5 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[CompositeAfterPaint] Fix cc::PictureLayer::GetPicture()

Previously it used RecordSource and RasterSource which did some extra
work not needed and caused DCHECK failure in CompositeAfterPaint when one
DisplayItemList was handled by RecordSource and RasterSource more than
once. In CompositeAfterPaint,
ContentLayerClient::PaintContentsToDisplayList() just returns the cached
DisplayItemList.

Simplify cc::PictureLayer::GetPicture() by directly calling
DisplayItemList::Raster().

Change-Id: I17cbf004371861ef901c95d21011f1bc9b07f880
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2142695Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758342}
parent 88d435bc
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_impl.h" #include "cc/trees/layer_tree_impl.h"
#include "cc/trees/transform_node.h" #include "cc/trees/transform_node.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/rect_conversions.h"
namespace cc { namespace cc {
...@@ -158,33 +159,18 @@ bool PictureLayer::Update() { ...@@ -158,33 +159,18 @@ bool PictureLayer::Update() {
} }
sk_sp<SkPicture> PictureLayer::GetPicture() const { sk_sp<SkPicture> PictureLayer::GetPicture() const {
// We could either flatten the RecordingSource into a single SkPicture, or if (!DrawsContent() || bounds().IsEmpty())
// paint a fresh one depending on what we intend to do with it. For now we
// just paint a fresh one to get consistent results.
if (!DrawsContent())
return nullptr; return nullptr;
gfx::Size layer_size = bounds();
RecordingSource recording_source;
Region recording_invalidation;
gfx::Rect new_recorded_viewport =
picture_layer_inputs_.client->PaintableRegion();
scoped_refptr<DisplayItemList> display_list = scoped_refptr<DisplayItemList> display_list =
picture_layer_inputs_.client->PaintContentsToDisplayList( picture_layer_inputs_.client->PaintContentsToDisplayList(
ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
size_t painter_reported_memory_usage = SkPictureRecorder recorder;
picture_layer_inputs_.client->GetApproximateUnsharedMemoryUsage(); SkCanvas* canvas =
recorder.beginRecording(bounds().width(), bounds().height());
recording_source.UpdateAndExpandInvalidation( canvas->clear(SK_ColorTRANSPARENT);
&recording_invalidation, layer_size, new_recorded_viewport); display_list->Raster(canvas);
recording_source.UpdateDisplayItemList( return recorder.finishRecordingAsPicture();
display_list, painter_reported_memory_usage,
layer_tree_host()->recording_scale_factor());
scoped_refptr<RasterSource> raster_source =
recording_source.CreateRasterSource();
return raster_source->GetFlattenedPicture();
} }
void PictureLayer::ClearClient() { void PictureLayer::ClearClient() {
......
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
#include "cc/paint/skia_paint_canvas.h" #include "cc/paint/skia_paint_canvas.h"
#include "components/viz/common/traced_value.h" #include "components/viz/common/traced_value.h"
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "ui/gfx/geometry/axis_transform2d.h" #include "ui/gfx/geometry/axis_transform2d.h"
#include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/rect_conversions.h"
namespace cc { namespace cc {
RasterSource::RasterSource(const RecordingSource* other) RasterSource::RasterSource(const RecordingSource* other)
: display_list_(other->display_list_), : display_list_(other->display_list_),
painter_reported_memory_usage_(other->painter_reported_memory_usage_), painter_reported_memory_usage_(other->painter_reported_memory_usage_),
...@@ -33,6 +33,7 @@ RasterSource::RasterSource(const RecordingSource* other) ...@@ -33,6 +33,7 @@ RasterSource::RasterSource(const RecordingSource* other)
slow_down_raster_scale_factor_for_debug_( slow_down_raster_scale_factor_for_debug_(
other->slow_down_raster_scale_factor_for_debug_), other->slow_down_raster_scale_factor_for_debug_),
recording_scale_factor_(other->recording_scale_factor_) {} recording_scale_factor_(other->recording_scale_factor_) {}
RasterSource::~RasterSource() = default; RasterSource::~RasterSource() = default;
void RasterSource::ClearForOpaqueRaster( void RasterSource::ClearForOpaqueRaster(
...@@ -146,19 +147,6 @@ void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas, ...@@ -146,19 +147,6 @@ void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas,
display_list_->Raster(raster_canvas, image_provider); display_list_->Raster(raster_canvas, image_provider);
} }
sk_sp<SkPicture> RasterSource::GetFlattenedPicture() {
TRACE_EVENT0("cc", "RasterSource::GetFlattenedPicture");
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(size_.width(), size_.height());
if (!size_.IsEmpty()) {
canvas->clear(SK_ColorTRANSPARENT);
PlaybackToCanvas(canvas, nullptr);
}
return recorder.finishRecordingAsPicture();
}
size_t RasterSource::GetMemoryUsage() const { size_t RasterSource::GetMemoryUsage() const {
if (!display_list_) if (!display_list_)
return 0; return 0;
......
...@@ -109,7 +109,6 @@ class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> { ...@@ -109,7 +109,6 @@ class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> {
// Tracing functionality. // Tracing functionality.
void DidBeginTracing(); void DidBeginTracing();
void AsValueInto(base::trace_event::TracedValue* array) const; void AsValueInto(base::trace_event::TracedValue* array) const;
sk_sp<SkPicture> GetFlattenedPicture();
size_t GetMemoryUsage() const; size_t GetMemoryUsage() const;
const scoped_refptr<DisplayItemList>& GetDisplayItemList() const { const scoped_refptr<DisplayItemList>& GetDisplayItemList() const {
......
...@@ -87,9 +87,6 @@ paint/invalidation/media-audio-no-spurious-repaints.html [ Failure ] ...@@ -87,9 +87,6 @@ paint/invalidation/media-audio-no-spurious-repaints.html [ Failure ]
crbug.com/940033 virtual/threaded-prefer-compositing/fast/scrolling/wheel-scrolling-over-custom-scrollbar.html [ Pass Failure ] crbug.com/940033 virtual/threaded-prefer-compositing/fast/scrolling/wheel-scrolling-over-custom-scrollbar.html [ Pass Failure ]
# Crash during PictureLayer::GetPicture() when DisplayItemList is finished twice.
http/tests/devtools/layers/layer-canvas-log.js [ Crash ]
http/tests/devtools/layers/layer-replay-scale.js [ Crash ]
# Missing compositing reasons # Missing compositing reasons
http/tests/devtools/layers/layer-compositing-reasons.js [ Failure ] http/tests/devtools/layers/layer-compositing-reasons.js [ Failure ]
# Missing WheelEventHandler # Missing WheelEventHandler
...@@ -102,7 +99,6 @@ crbug.com/1047358 paint/pagination/composited-paginated-outlined-box.html [ Fail ...@@ -102,7 +99,6 @@ crbug.com/1047358 paint/pagination/composited-paginated-outlined-box.html [ Fail
crbug.com/1047359 http/tests/subresource_filter/ad-highlight-frame-resized.html [ Failure ] crbug.com/1047359 http/tests/subresource_filter/ad-highlight-frame-resized.html [ Failure ]
virtual/threaded/fast/scroll-snap/snaps-after-touchpad-scrolling.html [ Failure ] virtual/threaded/fast/scroll-snap/snaps-after-touchpad-scrolling.html [ Failure ]
http/tests/devtools/a11y-axe-core/layers/layers-a11y-test.js [ Crash ]
# DCHECK(latched_scroll_type_.has_value()) in LayerTreeHostImpl::ScrollLatchedScroller(). # DCHECK(latched_scroll_type_.has_value()) in LayerTreeHostImpl::ScrollLatchedScroller().
crbug.com/1041322 virtual/threaded/synthetic_gestures/synthetic-pinch-zoom-gesture-touchscreen-desktop.html [ Crash ] crbug.com/1041322 virtual/threaded/synthetic_gestures/synthetic-pinch-zoom-gesture-touchscreen-desktop.html [ Crash ]
......
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