Commit ba47b3eb authored by schenney's avatar schenney Committed by Commit bot

Resolve FIXMEs in cc for Display Item Lists.

This is the final patch for removing location and making
SkPicture const in drawing display items, and the first patch
in adding scroll display item support in cc.

R=ajuma@chromium.org
BUG=458240

Review URL: https://codereview.chromium.org/939463003

Cr-Commit-Position: refs/heads/master@{#317060}
parent 6e4300d8
...@@ -35,14 +35,7 @@ scoped_refptr<cc::DisplayItemList> WebDisplayItemListImpl::ToDisplayItemList() { ...@@ -35,14 +35,7 @@ scoped_refptr<cc::DisplayItemList> WebDisplayItemListImpl::ToDisplayItemList() {
void WebDisplayItemListImpl::appendDrawingItem(const SkPicture* picture) { void WebDisplayItemListImpl::appendDrawingItem(const SkPicture* picture) {
display_item_list_->AppendItem(cc::DrawingDisplayItem::Create( display_item_list_->AppendItem(cc::DrawingDisplayItem::Create(
skia::SharePtr(const_cast<SkPicture*>(picture)), gfx::PointF(0, 0))); skia::SharePtr(const_cast<SkPicture*>(picture))));
}
void WebDisplayItemListImpl::appendDrawingItem(
SkPicture* picture,
const blink::WebFloatPoint& location) {
display_item_list_->AppendItem(
cc::DrawingDisplayItem::Create(skia::SharePtr(picture), location));
} }
void WebDisplayItemListImpl::appendClipItem( void WebDisplayItemListImpl::appendClipItem(
...@@ -114,6 +107,18 @@ void WebDisplayItemListImpl::appendEndFilterItem() { ...@@ -114,6 +107,18 @@ void WebDisplayItemListImpl::appendEndFilterItem() {
display_item_list_->AppendItem(cc::EndFilterDisplayItem::Create()); display_item_list_->AppendItem(cc::EndFilterDisplayItem::Create());
} }
void WebDisplayItemListImpl::appendScrollItem(
const blink::WebSize& scrollOffset,
ScrollContainerId) {
SkMatrix44 matrix;
matrix.setTranslate(-scrollOffset.width, -scrollOffset.height, 0);
appendTransformItem(matrix);
}
void WebDisplayItemListImpl::appendEndScrollItem() {
appendEndTransformItem();
}
WebDisplayItemListImpl::~WebDisplayItemListImpl() { WebDisplayItemListImpl::~WebDisplayItemListImpl() {
} }
......
...@@ -33,8 +33,6 @@ class WebDisplayItemListImpl : public blink::WebDisplayItemList { ...@@ -33,8 +33,6 @@ class WebDisplayItemListImpl : public blink::WebDisplayItemList {
// blink::WebDisplayItemList implementation. // blink::WebDisplayItemList implementation.
virtual void appendDrawingItem(const SkPicture*); virtual void appendDrawingItem(const SkPicture*);
virtual void appendDrawingItem(SkPicture*,
const blink::WebFloatPoint& location);
virtual void appendClipItem( virtual void appendClipItem(
const blink::WebRect& clip_rect, const blink::WebRect& clip_rect,
const blink::WebVector<SkRRect>& rounded_clip_rects); const blink::WebVector<SkRRect>& rounded_clip_rects);
...@@ -53,6 +51,9 @@ class WebDisplayItemListImpl : public blink::WebDisplayItemList { ...@@ -53,6 +51,9 @@ class WebDisplayItemListImpl : public blink::WebDisplayItemList {
virtual void appendFilterItem(const blink::WebFilterOperations& filters, virtual void appendFilterItem(const blink::WebFilterOperations& filters,
const blink::WebFloatRect& bounds); const blink::WebFloatRect& bounds);
virtual void appendEndFilterItem(); virtual void appendEndFilterItem();
virtual void appendScrollItem(const blink::WebSize& scrollOffset,
ScrollContainerId);
virtual void appendEndScrollItem();
private: private:
scoped_refptr<cc::DisplayItemList> display_item_list_; scoped_refptr<cc::DisplayItemList> display_item_list_;
......
...@@ -73,8 +73,7 @@ scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList( ...@@ -73,8 +73,7 @@ scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList(
PaintContents(canvas, clip, painting_control); PaintContents(canvas, clip, painting_control);
skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording());
display_item_list->AppendItem( display_item_list->AppendItem(DrawingDisplayItem::Create(picture));
DrawingDisplayItem::Create(picture, gfx::Point()));
return display_item_list; return display_item_list;
} }
......
...@@ -37,13 +37,15 @@ TEST(DisplayItemListTest, SingleDrawingItem) { ...@@ -37,13 +37,15 @@ TEST(DisplayItemListTest, SingleDrawingItem) {
unsigned char pixels[4 * 100 * 100] = {0}; unsigned char pixels[4 * 100 * 100] = {0};
scoped_refptr<DisplayItemList> list = DisplayItemList::Create(); scoped_refptr<DisplayItemList> list = DisplayItemList::Create();
gfx::PointF offset(8.f, 9.f);
gfx::RectF recording_rect(offset, layer_rect.size());
canvas = skia::SharePtr( canvas = skia::SharePtr(
recorder.beginRecording(layer_rect.width(), layer_rect.height())); recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
canvas->translate(offset.x(), offset.y());
canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
picture = skia::AdoptRef(recorder.endRecording()); picture = skia::AdoptRef(recorder.endRecording());
gfx::PointF offset(8.f, 9.f); list->AppendItem(DrawingDisplayItem::Create(picture));
list->AppendItem(DrawingDisplayItem::Create(picture, offset));
DrawDisplayList(pixels, layer_rect, list); DrawDisplayList(pixels, layer_rect, list);
SkBitmap expected_bitmap; SkBitmap expected_bitmap;
...@@ -75,22 +77,26 @@ TEST(DisplayItemListTest, ClipItem) { ...@@ -75,22 +77,26 @@ TEST(DisplayItemListTest, ClipItem) {
unsigned char pixels[4 * 100 * 100] = {0}; unsigned char pixels[4 * 100 * 100] = {0};
scoped_refptr<DisplayItemList> list = DisplayItemList::Create(); scoped_refptr<DisplayItemList> list = DisplayItemList::Create();
gfx::PointF first_offset(8.f, 9.f);
gfx::RectF first_recording_rect(first_offset, layer_rect.size());
canvas = skia::SharePtr( canvas = skia::SharePtr(
recorder.beginRecording(layer_rect.width(), layer_rect.height())); recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
canvas->translate(first_offset.x(), first_offset.y());
canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
picture = skia::AdoptRef(recorder.endRecording()); picture = skia::AdoptRef(recorder.endRecording());
gfx::PointF first_offset(8.f, 9.f); list->AppendItem(DrawingDisplayItem::Create(picture));
list->AppendItem(DrawingDisplayItem::Create(picture, first_offset));
gfx::Rect clip_rect(60, 60, 10, 10); gfx::Rect clip_rect(60, 60, 10, 10);
list->AppendItem(ClipDisplayItem::Create(clip_rect, std::vector<SkRRect>())); list->AppendItem(ClipDisplayItem::Create(clip_rect, std::vector<SkRRect>()));
gfx::PointF second_offset(2.f, 3.f);
gfx::RectF second_recording_rect(second_offset, layer_rect.size());
canvas = skia::SharePtr( canvas = skia::SharePtr(
recorder.beginRecording(layer_rect.width(), layer_rect.height())); recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)));
canvas->translate(second_offset.x(), second_offset.y());
canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
picture = skia::AdoptRef(recorder.endRecording()); picture = skia::AdoptRef(recorder.endRecording());
gfx::PointF second_offset(2.f, 3.f); list->AppendItem(DrawingDisplayItem::Create(picture));
list->AppendItem(DrawingDisplayItem::Create(picture, second_offset));
list->AppendItem(EndClipDisplayItem::Create()); list->AppendItem(EndClipDisplayItem::Create());
...@@ -126,23 +132,27 @@ TEST(DisplayItemListTest, TransformItem) { ...@@ -126,23 +132,27 @@ TEST(DisplayItemListTest, TransformItem) {
unsigned char pixels[4 * 100 * 100] = {0}; unsigned char pixels[4 * 100 * 100] = {0};
scoped_refptr<DisplayItemList> list = DisplayItemList::Create(); scoped_refptr<DisplayItemList> list = DisplayItemList::Create();
gfx::PointF first_offset(8.f, 9.f);
gfx::RectF first_recording_rect(first_offset, layer_rect.size());
canvas = skia::SharePtr( canvas = skia::SharePtr(
recorder.beginRecording(layer_rect.width(), layer_rect.height())); recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
canvas->translate(first_offset.x(), first_offset.y());
canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
picture = skia::AdoptRef(recorder.endRecording()); picture = skia::AdoptRef(recorder.endRecording());
gfx::PointF first_offset(8.f, 9.f); list->AppendItem(DrawingDisplayItem::Create(picture));
list->AppendItem(DrawingDisplayItem::Create(picture, first_offset));
gfx::Transform transform; gfx::Transform transform;
transform.Rotate(45.0); transform.Rotate(45.0);
list->AppendItem(TransformDisplayItem::Create(transform)); list->AppendItem(TransformDisplayItem::Create(transform));
gfx::PointF second_offset(2.f, 3.f);
gfx::RectF second_recording_rect(second_offset, layer_rect.size());
canvas = skia::SharePtr( canvas = skia::SharePtr(
recorder.beginRecording(layer_rect.width(), layer_rect.height())); recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)));
canvas->translate(second_offset.x(), second_offset.y());
canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
picture = skia::AdoptRef(recorder.endRecording()); picture = skia::AdoptRef(recorder.endRecording());
gfx::PointF second_offset(2.f, 3.f); list->AppendItem(DrawingDisplayItem::Create(picture));
list->AppendItem(DrawingDisplayItem::Create(picture, second_offset));
list->AppendItem(EndTransformDisplayItem::Create()); list->AppendItem(EndTransformDisplayItem::Create());
......
...@@ -17,9 +17,8 @@ ...@@ -17,9 +17,8 @@
namespace cc { namespace cc {
DrawingDisplayItem::DrawingDisplayItem(skia::RefPtr<SkPicture> picture, DrawingDisplayItem::DrawingDisplayItem(skia::RefPtr<SkPicture> picture)
gfx::PointF location) : picture_(picture) {
: picture_(picture), location_(location) {
} }
DrawingDisplayItem::~DrawingDisplayItem() { DrawingDisplayItem::~DrawingDisplayItem() {
...@@ -28,7 +27,6 @@ DrawingDisplayItem::~DrawingDisplayItem() { ...@@ -28,7 +27,6 @@ DrawingDisplayItem::~DrawingDisplayItem() {
void DrawingDisplayItem::Raster(SkCanvas* canvas, void DrawingDisplayItem::Raster(SkCanvas* canvas,
SkDrawPictureCallback* callback) const { SkDrawPictureCallback* callback) const {
canvas->save(); canvas->save();
canvas->translate(location_.x(), location_.y());
if (callback) if (callback)
picture_->playback(canvas, callback); picture_->playback(canvas, callback);
else else
...@@ -38,7 +36,6 @@ void DrawingDisplayItem::Raster(SkCanvas* canvas, ...@@ -38,7 +36,6 @@ void DrawingDisplayItem::Raster(SkCanvas* canvas,
void DrawingDisplayItem::RasterForTracing(SkCanvas* canvas) const { void DrawingDisplayItem::RasterForTracing(SkCanvas* canvas) const {
canvas->save(); canvas->save();
canvas->translate(location_.x(), location_.y());
// The picture debugger in about:tracing doesn't drill down into |drawPicture| // The picture debugger in about:tracing doesn't drill down into |drawPicture|
// operations. Calling |playback()| rather than |drawPicture()| causes the // operations. Calling |playback()| rather than |drawPicture()| causes the
// skia operations in |picture_| to appear individually in the picture // skia operations in |picture_| to appear individually in the picture
...@@ -53,7 +50,7 @@ bool DrawingDisplayItem::IsSuitableForGpuRasterization() const { ...@@ -53,7 +50,7 @@ bool DrawingDisplayItem::IsSuitableForGpuRasterization() const {
} }
int DrawingDisplayItem::ApproximateOpCount() const { int DrawingDisplayItem::ApproximateOpCount() const {
return picture_->approximateOpCount() + sizeof(gfx::PointF); return picture_->approximateOpCount();
} }
size_t DrawingDisplayItem::PictureMemoryUsage() const { size_t DrawingDisplayItem::PictureMemoryUsage() const {
...@@ -65,9 +62,11 @@ void DrawingDisplayItem::AsValueInto( ...@@ -65,9 +62,11 @@ void DrawingDisplayItem::AsValueInto(
base::trace_event::TracedValue* array) const { base::trace_event::TracedValue* array) const {
array->BeginDictionary(); array->BeginDictionary();
array->SetString("name", "DrawingDisplayItem"); array->SetString("name", "DrawingDisplayItem");
array->SetString("location", array->SetString(
base::StringPrintf("[%f,%f]", picture_->cullRect().x(), "cullRect",
picture_->cullRect().y())); base::StringPrintf("[%f,%f,%f,%f]", picture_->cullRect().x(),
picture_->cullRect().y(), picture_->cullRect().width(),
picture_->cullRect().height()));
std::string b64_picture; std::string b64_picture;
PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture);
array->SetString("skp64", b64_picture); array->SetString("skp64", b64_picture);
......
...@@ -21,9 +21,9 @@ class CC_EXPORT DrawingDisplayItem : public DisplayItem { ...@@ -21,9 +21,9 @@ class CC_EXPORT DrawingDisplayItem : public DisplayItem {
public: public:
~DrawingDisplayItem() override; ~DrawingDisplayItem() override;
static scoped_ptr<DrawingDisplayItem> Create(skia::RefPtr<SkPicture> picture, static scoped_ptr<DrawingDisplayItem> Create(
gfx::PointF location) { skia::RefPtr<SkPicture> picture) {
return make_scoped_ptr(new DrawingDisplayItem(picture, location)); return make_scoped_ptr(new DrawingDisplayItem(picture));
} }
void Raster(SkCanvas* canvas, SkDrawPictureCallback* callback) const override; void Raster(SkCanvas* canvas, SkDrawPictureCallback* callback) const override;
...@@ -35,11 +35,10 @@ class CC_EXPORT DrawingDisplayItem : public DisplayItem { ...@@ -35,11 +35,10 @@ class CC_EXPORT DrawingDisplayItem : public DisplayItem {
void AsValueInto(base::trace_event::TracedValue* array) const override; void AsValueInto(base::trace_event::TracedValue* array) const override;
protected: protected:
DrawingDisplayItem(skia::RefPtr<SkPicture> picture, gfx::PointF location); explicit DrawingDisplayItem(skia::RefPtr<SkPicture> picture);
private: private:
skia::RefPtr<SkPicture> picture_; skia::RefPtr<SkPicture> picture_;
gfx::PointF location_;
}; };
} // namespace cc } // namespace cc
......
...@@ -69,13 +69,12 @@ FakeContentLayerClient::PaintContentsToDisplayList( ...@@ -69,13 +69,12 @@ FakeContentLayerClient::PaintContentsToDisplayList(
it != draw_rects_.end(); ++it) { it != draw_rects_.end(); ++it) {
const gfx::RectF& draw_rect = it->first; const gfx::RectF& draw_rect = it->first;
const SkPaint& paint = it->second; const SkPaint& paint = it->second;
canvas = skia::SharePtr( canvas =
recorder.beginRecording(draw_rect.width(), draw_rect.height())); skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect)));
canvas->drawRectCoords(0.f, 0.f, draw_rect.width(), draw_rect.height(), canvas->drawRectCoords(0.f, 0.f, draw_rect.width(), draw_rect.height(),
paint); paint);
picture = skia::AdoptRef(recorder.endRecording()); picture = skia::AdoptRef(recorder.endRecording());
list->AppendItem(DrawingDisplayItem::Create( list->AppendItem(DrawingDisplayItem::Create(picture));
picture, gfx::PointF(draw_rect.x(), draw_rect.y())));
} }
for (BitmapVector::const_iterator it = draw_bitmaps_.begin(); for (BitmapVector::const_iterator it = draw_bitmaps_.begin();
...@@ -84,8 +83,7 @@ FakeContentLayerClient::PaintContentsToDisplayList( ...@@ -84,8 +83,7 @@ FakeContentLayerClient::PaintContentsToDisplayList(
recorder.beginRecording(it->bitmap.width(), it->bitmap.height())); recorder.beginRecording(it->bitmap.width(), it->bitmap.height()));
canvas->drawBitmap(it->bitmap, 0.f, 0.f, &it->paint); canvas->drawBitmap(it->bitmap, 0.f, 0.f, &it->paint);
picture = skia::AdoptRef(recorder.endRecording()); picture = skia::AdoptRef(recorder.endRecording());
list->AppendItem(DrawingDisplayItem::Create( list->AppendItem(DrawingDisplayItem::Create(picture));
picture, gfx::PointF(it->point.x(), it->point.y())));
} }
if (fill_with_nonsolid_color_) { if (fill_with_nonsolid_color_) {
...@@ -94,11 +92,11 @@ FakeContentLayerClient::PaintContentsToDisplayList( ...@@ -94,11 +92,11 @@ FakeContentLayerClient::PaintContentsToDisplayList(
while (!draw_rect.IsEmpty()) { while (!draw_rect.IsEmpty()) {
SkPaint paint; SkPaint paint;
paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); paint.setColor(red ? SK_ColorRED : SK_ColorBLUE);
canvas = canvas = skia::SharePtr(
skia::SharePtr(recorder.beginRecording(clip.width(), clip.height())); recorder.beginRecording(gfx::RectFToSkRect(draw_rect)));
canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint);
picture = skia::AdoptRef(recorder.endRecording()); picture = skia::AdoptRef(recorder.endRecording());
list->AppendItem(DrawingDisplayItem::Create(picture, gfx::PointF())); list->AppendItem(DrawingDisplayItem::Create(picture));
draw_rect.Inset(1, 1); draw_rect.Inset(1, 1);
} }
} }
......
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