| 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" | 12 #include "cc/proto/display_item.pb.h" |
| 13 #include "cc/proto/gfx_conversions.h" | 13 #include "cc/proto/gfx_conversions.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "third_party/skia/include/core/SkImageFilter.h" | 15 #include "third_party/skia/include/core/SkImageFilter.h" |
| 16 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "third_party/skia/include/core/SkPaint.h" |
| 17 #include "third_party/skia/include/core/SkRefCnt.h" | 17 #include "third_party/skia/include/core/SkRefCnt.h" |
| 18 #include "third_party/skia/include/core/SkXfermode.h" | 18 #include "third_party/skia/include/core/SkXfermode.h" |
| 19 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
| 20 | 20 |
| 21 namespace cc { | 21 namespace cc { |
| 22 | 22 |
| 23 FilterDisplayItem::FilterDisplayItem(const FilterOperations& filters, | 23 FilterDisplayItem::FilterDisplayItem(const FilterOperations& filters, |
| 24 const gfx::RectF& bounds) { | 24 const gfx::RectF& bounds, |
| 25 SetNew(filters, bounds); | 25 const gfx::PointF& origin) { |
| 26 SetNew(filters, bounds, origin); |
| 26 } | 27 } |
| 27 | 28 |
| 28 FilterDisplayItem::FilterDisplayItem(const proto::DisplayItem& proto) { | 29 FilterDisplayItem::FilterDisplayItem(const proto::DisplayItem& proto) { |
| 29 DCHECK_EQ(proto::DisplayItem::Type_Filter, proto.type()); | 30 DCHECK_EQ(proto::DisplayItem::Type_Filter, proto.type()); |
| 30 | 31 |
| 31 const proto::FilterDisplayItem& details = proto.filter_item(); | 32 const proto::FilterDisplayItem& details = proto.filter_item(); |
| 32 gfx::RectF bounds = ProtoToRectF(details.bounds()); | 33 gfx::RectF bounds = ProtoToRectF(details.bounds()); |
| 33 | 34 |
| 34 // TODO(dtrainor): Support deserializing FilterOperations (crbug.com/541321). | 35 // TODO(dtrainor): Support deserializing FilterOperations (crbug.com/541321). |
| 35 FilterOperations filters; | 36 FilterOperations filters; |
| 36 | 37 gfx::PointF origin(.0f, .0f); // TODO(senorblanco): Support origin. |
| 37 SetNew(filters, bounds); | 38 SetNew(filters, bounds, origin); |
| 38 } | 39 } |
| 39 | 40 |
| 40 FilterDisplayItem::~FilterDisplayItem() {} | 41 FilterDisplayItem::~FilterDisplayItem() {} |
| 41 | 42 |
| 42 void FilterDisplayItem::SetNew(const FilterOperations& filters, | 43 void FilterDisplayItem::SetNew(const FilterOperations& filters, |
| 43 const gfx::RectF& bounds) { | 44 const gfx::RectF& bounds, |
| 45 const gfx::PointF& origin) { |
| 44 filters_ = filters; | 46 filters_ = filters; |
| 45 bounds_ = bounds; | 47 bounds_ = bounds; |
| 48 origin_ = origin; |
| 46 } | 49 } |
| 47 | 50 |
| 48 void FilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 51 void FilterDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
| 49 proto->set_type(proto::DisplayItem::Type_Filter); | 52 proto->set_type(proto::DisplayItem::Type_Filter); |
| 50 | 53 |
| 51 proto::FilterDisplayItem* details = proto->mutable_filter_item(); | 54 proto::FilterDisplayItem* details = proto->mutable_filter_item(); |
| 52 RectFToProto(bounds_, details->mutable_bounds()); | 55 RectFToProto(bounds_, details->mutable_bounds()); |
| 53 | 56 |
| 54 // TODO(dtrainor): Support serializing FilterOperations (crbug.com/541321). | 57 // TODO(dtrainor): Support serializing FilterOperations (crbug.com/541321). |
| 55 } | 58 } |
| 56 | 59 |
| 57 void FilterDisplayItem::Raster(SkCanvas* canvas, | 60 void FilterDisplayItem::Raster(SkCanvas* canvas, |
| 58 SkPicture::AbortCallback* callback) const { | 61 SkPicture::AbortCallback* callback) const { |
| 59 canvas->save(); | 62 canvas->save(); |
| 60 canvas->translate(bounds_.x(), bounds_.y()); | 63 canvas->translate(origin_.x(), origin_.y()); |
| 61 | 64 |
| 62 sk_sp<SkImageFilter> image_filter = RenderSurfaceFilters::BuildImageFilter( | 65 sk_sp<SkImageFilter> image_filter = RenderSurfaceFilters::BuildImageFilter( |
| 63 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); | 66 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); |
| 64 SkRect boundaries = SkRect::MakeWH(bounds_.width(), bounds_.height()); | 67 SkRect boundaries = RectFToSkRect(bounds_); |
| 68 boundaries.offset(-origin_.x(), -origin_.y()); |
| 65 | 69 |
| 66 SkPaint paint; | 70 SkPaint paint; |
| 67 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 71 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
| 68 paint.setImageFilter(std::move(image_filter)); | 72 paint.setImageFilter(std::move(image_filter)); |
| 69 canvas->saveLayer(&boundaries, &paint); | 73 canvas->saveLayer(&boundaries, &paint); |
| 70 | 74 |
| 71 canvas->translate(-bounds_.x(), -bounds_.y()); | 75 canvas->translate(-origin_.x(), -origin_.y()); |
| 72 } | 76 } |
| 73 | 77 |
| 74 void FilterDisplayItem::AsValueInto( | 78 void FilterDisplayItem::AsValueInto( |
| 75 const gfx::Rect& visual_rect, | 79 const gfx::Rect& visual_rect, |
| 76 base::trace_event::TracedValue* array) const { | 80 base::trace_event::TracedValue* array) const { |
| 77 array->AppendString(base::StringPrintf( | 81 array->AppendString(base::StringPrintf( |
| 78 "FilterDisplayItem bounds: [%s] visualRect: [%s]", | 82 "FilterDisplayItem bounds: [%s] visualRect: [%s]", |
| 79 bounds_.ToString().c_str(), visual_rect.ToString().c_str())); | 83 bounds_.ToString().c_str(), visual_rect.ToString().c_str())); |
| 80 } | 84 } |
| 81 | 85 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 109 array->AppendString( | 113 array->AppendString( |
| 110 base::StringPrintf("EndFilterDisplayItem visualRect: [%s]", | 114 base::StringPrintf("EndFilterDisplayItem visualRect: [%s]", |
| 111 visual_rect.ToString().c_str())); | 115 visual_rect.ToString().c_str())); |
| 112 } | 116 } |
| 113 | 117 |
| 114 size_t EndFilterDisplayItem::ExternalMemoryUsage() const { | 118 size_t EndFilterDisplayItem::ExternalMemoryUsage() const { |
| 115 return 0; | 119 return 0; |
| 116 } | 120 } |
| 117 | 121 |
| 118 } // namespace cc | 122 } // namespace cc |
| OLD | NEW |