Commit 3b15b1df authored by Adrienne Walker's avatar Adrienne Walker Committed by Commit Bot

Expose RasterSource preamble generation

This refactors RasterSource to make it possibly to reuse the preamble
of transform/clip/clearing that it does when moving raster to the
gpu process.  The followup to this patch will be to use this
preamble and send it as its own PaintOpBuffer ahead of the
PaintOpBuffer that gets rastered.

Bug: 671433
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ia2139f82ad0186df22afeb120fa8944625971ef9
Reviewed-on: https://chromium-review.googlesource.com/592237
Commit-Queue: enne <enne@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491487}
parent 5e19e835
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "cc/debug/debug_colors.h" #include "cc/debug/debug_colors.h"
#include "cc/debug/traced_value.h" #include "cc/debug/traced_value.h"
#include "cc/paint/display_item_list.h" #include "cc/paint/display_item_list.h"
#include "cc/paint/skia_paint_canvas.h"
#include "skia/ext/analysis_canvas.h" #include "skia/ext/analysis_canvas.h"
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColorSpaceXformCanvas.h" #include "third_party/skia/include/core/SkColorSpaceXformCanvas.h"
...@@ -35,6 +36,22 @@ RasterSource::RasterSource(const RecordingSource* other) ...@@ -35,6 +36,22 @@ RasterSource::RasterSource(const RecordingSource* other)
other->slow_down_raster_scale_factor_for_debug_) {} other->slow_down_raster_scale_factor_for_debug_) {}
RasterSource::~RasterSource() = default; RasterSource::~RasterSource() = default;
void RasterSource::SetupCanvasForRaster(
PaintCanvas* canvas,
const gfx::Rect& canvas_bitmap_rect,
const gfx::Rect& canvas_playback_rect,
const gfx::AxisTransform2d& raster_transform,
bool should_clear_canvas) const {
canvas->translate(-canvas_bitmap_rect.x(), -canvas_bitmap_rect.y());
canvas->clipRect(gfx::RectToSkRect(canvas_playback_rect));
canvas->translate(raster_transform.translation().x(),
raster_transform.translation().y());
canvas->scale(raster_transform.scale(), raster_transform.scale());
if (should_clear_canvas)
ClearCanvasForPlayback(canvas);
}
void RasterSource::PlaybackToCanvas( void RasterSource::PlaybackToCanvas(
SkCanvas* raster_canvas, SkCanvas* raster_canvas,
const gfx::ColorSpace& target_color_space, const gfx::ColorSpace& target_color_space,
...@@ -50,11 +67,9 @@ void RasterSource::PlaybackToCanvas( ...@@ -50,11 +67,9 @@ void RasterSource::PlaybackToCanvas(
ScopedSubnormalFloatDisabler disabler; ScopedSubnormalFloatDisabler disabler;
raster_canvas->save(); raster_canvas->save();
raster_canvas->translate(-canvas_bitmap_rect.x(), -canvas_bitmap_rect.y()); SkiaPaintCanvas paint_canvas(raster_canvas);
raster_canvas->clipRect(SkRect::MakeFromIRect(raster_bounds)); SetupCanvasForRaster(&paint_canvas, canvas_bitmap_rect, canvas_playback_rect,
raster_canvas->translate(raster_transform.translation().x(), raster_transform, !settings.playback_to_shared_canvas);
raster_transform.translation().y());
raster_canvas->scale(raster_transform.scale(), raster_transform.scale());
PlaybackToCanvas(raster_canvas, target_color_space, settings); PlaybackToCanvas(raster_canvas, target_color_space, settings);
raster_canvas->restore(); raster_canvas->restore();
} }
...@@ -62,6 +77,7 @@ void RasterSource::PlaybackToCanvas( ...@@ -62,6 +77,7 @@ void RasterSource::PlaybackToCanvas(
void RasterSource::PlaybackToCanvas(SkCanvas* input_canvas, void RasterSource::PlaybackToCanvas(SkCanvas* input_canvas,
const gfx::ColorSpace& target_color_space, const gfx::ColorSpace& target_color_space,
const PlaybackSettings& settings) const { const PlaybackSettings& settings) const {
// TODO(enne): color transform needs to be replicated in gles2_cmd_decoder
SkCanvas* raster_canvas = input_canvas; SkCanvas* raster_canvas = input_canvas;
std::unique_ptr<SkCanvas> color_transform_canvas; std::unique_ptr<SkCanvas> color_transform_canvas;
if (target_color_space.IsValid()) { if (target_color_space.IsValid()) {
...@@ -70,15 +86,10 @@ void RasterSource::PlaybackToCanvas(SkCanvas* input_canvas, ...@@ -70,15 +86,10 @@ void RasterSource::PlaybackToCanvas(SkCanvas* input_canvas,
raster_canvas = color_transform_canvas.get(); raster_canvas = color_transform_canvas.get();
} }
if (!settings.playback_to_shared_canvas)
PrepareForPlaybackToCanvas(raster_canvas);
RasterCommon(raster_canvas, settings.image_provider); RasterCommon(raster_canvas, settings.image_provider);
} }
void RasterSource::PrepareForPlaybackToCanvas(SkCanvas* canvas) const { void RasterSource::ClearCanvasForPlayback(PaintCanvas* canvas) const {
// TODO(hendrikw): See if we can split this up into separate functions.
// If this raster source has opaque contents, it is guaranteeing that it will // If this raster source has opaque contents, it is guaranteeing that it will
// draw an opaque rect the size of the layer. If it is not, then we must // draw an opaque rect the size of the layer. If it is not, then we must
// clear this canvas ourselves. // clear this canvas ourselves.
...@@ -126,10 +137,9 @@ void RasterSource::PrepareForPlaybackToCanvas(SkCanvas* canvas) const { ...@@ -126,10 +137,9 @@ void RasterSource::PrepareForPlaybackToCanvas(SkCanvas* canvas) const {
// rerasterize a tile that used to intersect with the content rect // rerasterize a tile that used to intersect with the content rect
// after the content bounds grew. // after the content bounds grew.
canvas->save(); canvas->save();
// Use clipRegion to bypass CTM because the rects are device rects. // Use clipDeviceRect to bypass CTM because the rects are device rects.
SkRegion interest_region; canvas->clipDeviceRect(interest_rect, SkIRect::MakeEmpty(),
interest_region.setRect(interest_rect); SkClipOp::kDifference);
canvas->clipRegion(interest_region, SkClipOp::kDifference);
canvas->clear(DebugColors::MissingResizeInvalidations()); canvas->clear(DebugColors::MissingResizeInvalidations());
canvas->restore(); canvas->restore();
} }
...@@ -137,11 +147,8 @@ void RasterSource::PrepareForPlaybackToCanvas(SkCanvas* canvas) const { ...@@ -137,11 +147,8 @@ void RasterSource::PrepareForPlaybackToCanvas(SkCanvas* canvas) const {
// Drawing at most 2 x 2 x (canvas width + canvas height) texels is 2-3X // Drawing at most 2 x 2 x (canvas width + canvas height) texels is 2-3X
// faster than clearing, so special case this. // faster than clearing, so special case this.
canvas->save(); canvas->save();
// Use clipRegion to bypass CTM because the rects are device rects. // Use clipDeviceRect to bypass CTM because the rects are device rects.
SkRegion interest_region; canvas->clipDeviceRect(interest_rect, opaque_rect, SkClipOp::kIntersect);
interest_region.setRect(interest_rect);
interest_region.op(opaque_rect, SkRegion::kDifference_Op);
canvas->clipRegion(interest_region);
canvas->clear(background_color_); canvas->clear(background_color_);
canvas->restore(); canvas->restore();
} }
...@@ -161,7 +168,7 @@ sk_sp<SkPicture> RasterSource::GetFlattenedPicture() { ...@@ -161,7 +168,7 @@ sk_sp<SkPicture> RasterSource::GetFlattenedPicture() {
SkPictureRecorder recorder; SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(size_.width(), size_.height()); SkCanvas* canvas = recorder.beginRecording(size_.width(), size_.height());
if (!size_.IsEmpty()) { if (!size_.IsEmpty()) {
PrepareForPlaybackToCanvas(canvas); canvas->clear(SK_ColorTRANSPARENT);
RasterCommon(canvas); RasterCommon(canvas);
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "cc/debug/rendering_stats_instrumentation.h" #include "cc/debug/rendering_stats_instrumentation.h"
#include "cc/layers/recording_source.h" #include "cc/layers/recording_source.h"
#include "cc/paint/image_id.h" #include "cc/paint/image_id.h"
#include "cc/paint/paint_canvas.h"
#include "skia/ext/analysis_canvas.h" #include "skia/ext/analysis_canvas.h"
#include "third_party/skia/include/core/SkPicture.h" #include "third_party/skia/include/core/SkPicture.h"
#include "ui/gfx/color_space.h" #include "ui/gfx/color_space.h"
...@@ -47,6 +48,12 @@ class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> { ...@@ -47,6 +48,12 @@ class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> {
ImageProvider* image_provider = nullptr; ImageProvider* image_provider = nullptr;
}; };
void SetupCanvasForRaster(PaintCanvas* canvas,
const gfx::Rect& canvas_bitmap_rect,
const gfx::Rect& canvas_playback_rect,
const gfx::AxisTransform2d& raster_transform,
bool should_clear_canvas) const;
// Helper function to apply a few common operations before passing the canvas // Helper function to apply a few common operations before passing the canvas
// to the shorter version. This is useful for rastering into tiles. // to the shorter version. This is useful for rastering into tiles.
// canvas is expected to be backed by a tile, with a default state. // canvas is expected to be backed by a tile, with a default state.
...@@ -142,7 +149,7 @@ class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> { ...@@ -142,7 +149,7 @@ class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> {
ImageProvider* image_provider = nullptr, ImageProvider* image_provider = nullptr,
SkPicture::AbortCallback* callback = nullptr) const; SkPicture::AbortCallback* callback = nullptr) const;
void PrepareForPlaybackToCanvas(SkCanvas* canvas) const; void ClearCanvasForPlayback(PaintCanvas* canvas) const;
DISALLOW_COPY_AND_ASSIGN(RasterSource); DISALLOW_COPY_AND_ASSIGN(RasterSource);
}; };
......
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