| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/playback/filter_display_item.h" | 5 #include "cc/playback/filter_display_item.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/trace_event/trace_event_argument.h" | 10 #include "base/trace_event/trace_event_argument.h" |
| 11 #include "cc/output/render_surface_filters.h" | 11 #include "cc/output/render_surface_filters.h" |
| 12 #include "cc/proto/display_item.pb.h" | |
| 13 #include "cc/proto/gfx_conversions.h" | |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "third_party/skia/include/core/SkImageFilter.h" | 13 #include "third_party/skia/include/core/SkImageFilter.h" |
| 16 #include "third_party/skia/include/core/SkPaint.h" | 14 #include "third_party/skia/include/core/SkPaint.h" |
| 17 #include "third_party/skia/include/core/SkRefCnt.h" | 15 #include "third_party/skia/include/core/SkRefCnt.h" |
| 18 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
| 19 | 17 |
| 20 namespace cc { | 18 namespace cc { |
| 21 | 19 |
| 22 FilterDisplayItem::FilterDisplayItem(const FilterOperations& filters, | 20 FilterDisplayItem::FilterDisplayItem(const FilterOperations& filters, |
| 23 const gfx::RectF& bounds, | 21 const gfx::RectF& bounds, |
| 24 const gfx::PointF& origin) | 22 const gfx::PointF& origin) |
| 25 : DisplayItem(FILTER) { | 23 : DisplayItem(FILTER) { |
| 26 SetNew(filters, bounds, origin); | 24 SetNew(filters, bounds, origin); |
| 27 } | 25 } |
| 28 | 26 |
| 29 FilterDisplayItem::FilterDisplayItem(const proto::DisplayItem& proto) | |
| 30 : DisplayItem(FILTER) { | |
| 31 DCHECK_EQ(proto::DisplayItem::Type_Filter, proto.type()); | |
| 32 | |
| 33 const proto::FilterDisplayItem& details = proto.filter_item(); | |
| 34 gfx::RectF bounds = ProtoToRectF(details.bounds()); | |
| 35 | |
| 36 // TODO(dtrainor): Support deserializing FilterOperations (crbug.com/541321). | |
| 37 FilterOperations filters; | |
| 38 gfx::PointF origin(.0f, .0f); // TODO(senorblanco): Support origin. | |
| 39 SetNew(filters, bounds, origin); | |
| 40 } | |
| 41 | |
| 42 FilterDisplayItem::~FilterDisplayItem() {} | 27 FilterDisplayItem::~FilterDisplayItem() {} |
| 43 | 28 |
| 44 void FilterDisplayItem::SetNew(const FilterOperations& filters, | 29 void FilterDisplayItem::SetNew(const FilterOperations& filters, |
| 45 const gfx::RectF& bounds, | 30 const gfx::RectF& bounds, |
| 46 const gfx::PointF& origin) { | 31 const gfx::PointF& origin) { |
| 47 filters_ = filters; | 32 filters_ = filters; |
| 48 bounds_ = bounds; | 33 bounds_ = bounds; |
| 49 origin_ = origin; | 34 origin_ = origin; |
| 50 } | 35 } |
| 51 | 36 |
| 52 void FilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | |
| 53 proto->set_type(proto::DisplayItem::Type_Filter); | |
| 54 | |
| 55 proto::FilterDisplayItem* details = proto->mutable_filter_item(); | |
| 56 RectFToProto(bounds_, details->mutable_bounds()); | |
| 57 | |
| 58 // TODO(dtrainor): Support serializing FilterOperations (crbug.com/541321). | |
| 59 } | |
| 60 | |
| 61 void FilterDisplayItem::Raster(SkCanvas* canvas, | 37 void FilterDisplayItem::Raster(SkCanvas* canvas, |
| 62 SkPicture::AbortCallback* callback) const { | 38 SkPicture::AbortCallback* callback) const { |
| 63 canvas->save(); | 39 canvas->save(); |
| 64 canvas->translate(origin_.x(), origin_.y()); | 40 canvas->translate(origin_.x(), origin_.y()); |
| 65 | 41 |
| 66 sk_sp<SkImageFilter> image_filter = RenderSurfaceFilters::BuildImageFilter( | 42 sk_sp<SkImageFilter> image_filter = RenderSurfaceFilters::BuildImageFilter( |
| 67 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); | 43 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); |
| 68 SkRect boundaries = RectFToSkRect(bounds_); | 44 SkRect boundaries = RectFToSkRect(bounds_); |
| 69 boundaries.offset(-origin_.x(), -origin_.y()); | 45 boundaries.offset(-origin_.x(), -origin_.y()); |
| 70 | 46 |
| 71 SkPaint paint; | 47 SkPaint paint; |
| 72 paint.setBlendMode(SkBlendMode::kSrcOver); | 48 paint.setBlendMode(SkBlendMode::kSrcOver); |
| 73 paint.setImageFilter(std::move(image_filter)); | 49 paint.setImageFilter(std::move(image_filter)); |
| 74 canvas->saveLayer(&boundaries, &paint); | 50 canvas->saveLayer(&boundaries, &paint); |
| 75 | 51 |
| 76 canvas->translate(-origin_.x(), -origin_.y()); | 52 canvas->translate(-origin_.x(), -origin_.y()); |
| 77 } | 53 } |
| 78 | 54 |
| 79 void FilterDisplayItem::AsValueInto( | 55 void FilterDisplayItem::AsValueInto( |
| 80 const gfx::Rect& visual_rect, | 56 const gfx::Rect& visual_rect, |
| 81 base::trace_event::TracedValue* array) const { | 57 base::trace_event::TracedValue* array) const { |
| 82 array->AppendString(base::StringPrintf( | 58 array->AppendString(base::StringPrintf( |
| 83 "FilterDisplayItem bounds: [%s] visualRect: [%s]", | 59 "FilterDisplayItem bounds: [%s] visualRect: [%s]", |
| 84 bounds_.ToString().c_str(), visual_rect.ToString().c_str())); | 60 bounds_.ToString().c_str(), visual_rect.ToString().c_str())); |
| 85 } | 61 } |
| 86 | 62 |
| 87 EndFilterDisplayItem::EndFilterDisplayItem() : DisplayItem(END_FILTER) {} | 63 EndFilterDisplayItem::EndFilterDisplayItem() : DisplayItem(END_FILTER) {} |
| 88 | 64 |
| 89 EndFilterDisplayItem::EndFilterDisplayItem(const proto::DisplayItem& proto) | |
| 90 : DisplayItem(END_FILTER) { | |
| 91 DCHECK_EQ(proto::DisplayItem::Type_EndFilter, proto.type()); | |
| 92 } | |
| 93 | |
| 94 EndFilterDisplayItem::~EndFilterDisplayItem() {} | 65 EndFilterDisplayItem::~EndFilterDisplayItem() {} |
| 95 | 66 |
| 96 void EndFilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | |
| 97 proto->set_type(proto::DisplayItem::Type_EndFilter); | |
| 98 } | |
| 99 | |
| 100 void EndFilterDisplayItem::Raster(SkCanvas* canvas, | 67 void EndFilterDisplayItem::Raster(SkCanvas* canvas, |
| 101 SkPicture::AbortCallback* callback) const { | 68 SkPicture::AbortCallback* callback) const { |
| 102 canvas->restore(); | 69 canvas->restore(); |
| 103 canvas->restore(); | 70 canvas->restore(); |
| 104 } | 71 } |
| 105 | 72 |
| 106 void EndFilterDisplayItem::AsValueInto( | 73 void EndFilterDisplayItem::AsValueInto( |
| 107 const gfx::Rect& visual_rect, | 74 const gfx::Rect& visual_rect, |
| 108 base::trace_event::TracedValue* array) const { | 75 base::trace_event::TracedValue* array) const { |
| 109 array->AppendString( | 76 array->AppendString( |
| 110 base::StringPrintf("EndFilterDisplayItem visualRect: [%s]", | 77 base::StringPrintf("EndFilterDisplayItem visualRect: [%s]", |
| 111 visual_rect.ToString().c_str())); | 78 visual_rect.ToString().c_str())); |
| 112 } | 79 } |
| 113 | 80 |
| 114 } // namespace cc | 81 } // namespace cc |
| OLD | NEW |