| 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> | |
| 8 | |
| 9 #include "base/strings/stringprintf.h" | |
| 10 #include "base/trace_event/trace_event_argument.h" | |
| 11 #include "cc/output/render_surface_filters.h" | |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | |
| 13 #include "third_party/skia/include/core/SkImageFilter.h" | |
| 14 #include "third_party/skia/include/core/SkPaint.h" | |
| 15 #include "third_party/skia/include/core/SkRefCnt.h" | |
| 16 #include "ui/gfx/skia_util.h" | |
| 17 | |
| 18 namespace cc { | 7 namespace cc { |
| 19 | 8 |
| 20 FilterDisplayItem::FilterDisplayItem(const FilterOperations& filters, | 9 FilterDisplayItem::FilterDisplayItem(const FilterOperations& filters, |
| 21 const gfx::RectF& bounds, | 10 const gfx::RectF& bounds, |
| 22 const gfx::PointF& origin) | 11 const gfx::PointF& origin) |
| 23 : DisplayItem(FILTER) { | 12 : DisplayItem(FILTER), filters(filters), bounds(bounds), origin(origin) {} |
| 24 SetNew(filters, bounds, origin); | |
| 25 } | |
| 26 | 13 |
| 27 FilterDisplayItem::~FilterDisplayItem() {} | 14 FilterDisplayItem::~FilterDisplayItem() = default; |
| 28 | |
| 29 void FilterDisplayItem::SetNew(const FilterOperations& filters, | |
| 30 const gfx::RectF& bounds, | |
| 31 const gfx::PointF& origin) { | |
| 32 filters_ = filters; | |
| 33 bounds_ = bounds; | |
| 34 origin_ = origin; | |
| 35 } | |
| 36 | |
| 37 void FilterDisplayItem::Raster(SkCanvas* canvas, | |
| 38 SkPicture::AbortCallback* callback) const { | |
| 39 canvas->save(); | |
| 40 canvas->translate(origin_.x(), origin_.y()); | |
| 41 | |
| 42 sk_sp<SkImageFilter> image_filter = RenderSurfaceFilters::BuildImageFilter( | |
| 43 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); | |
| 44 SkRect boundaries = RectFToSkRect(bounds_); | |
| 45 boundaries.offset(-origin_.x(), -origin_.y()); | |
| 46 | |
| 47 SkPaint paint; | |
| 48 paint.setBlendMode(SkBlendMode::kSrcOver); | |
| 49 paint.setImageFilter(std::move(image_filter)); | |
| 50 canvas->saveLayer(&boundaries, &paint); | |
| 51 | |
| 52 canvas->translate(-origin_.x(), -origin_.y()); | |
| 53 } | |
| 54 | 15 |
| 55 EndFilterDisplayItem::EndFilterDisplayItem() : DisplayItem(END_FILTER) {} | 16 EndFilterDisplayItem::EndFilterDisplayItem() : DisplayItem(END_FILTER) {} |
| 56 | 17 |
| 57 EndFilterDisplayItem::~EndFilterDisplayItem() {} | 18 EndFilterDisplayItem::~EndFilterDisplayItem() = default; |
| 58 | |
| 59 void EndFilterDisplayItem::Raster(SkCanvas* canvas, | |
| 60 SkPicture::AbortCallback* callback) const { | |
| 61 canvas->restore(); | |
| 62 canvas->restore(); | |
| 63 } | |
| 64 | 19 |
| 65 } // namespace cc | 20 } // namespace cc |
| OLD | NEW |