| 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 "third_party/skia/include/core/SkCanvas.h" | 12 #include "cc/paint/paint_flags.h" |
| 13 #include "third_party/skia/include/core/SkImageFilter.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" | 14 #include "third_party/skia/include/core/SkRefCnt.h" |
| 16 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
| 17 | 16 |
| 18 namespace cc { | 17 namespace cc { |
| 19 | 18 |
| 20 FilterDisplayItem::FilterDisplayItem(const FilterOperations& filters, | 19 FilterDisplayItem::FilterDisplayItem(const FilterOperations& filters, |
| 21 const gfx::RectF& bounds, | 20 const gfx::RectF& bounds, |
| 22 const gfx::PointF& origin) | 21 const gfx::PointF& origin) |
| 23 : DisplayItem(FILTER) { | 22 : DisplayItem(FILTER) { |
| 24 SetNew(filters, bounds, origin); | 23 SetNew(filters, bounds, origin); |
| 25 } | 24 } |
| 26 | 25 |
| 27 FilterDisplayItem::~FilterDisplayItem() {} | 26 FilterDisplayItem::~FilterDisplayItem() {} |
| 28 | 27 |
| 29 void FilterDisplayItem::SetNew(const FilterOperations& filters, | 28 void FilterDisplayItem::SetNew(const FilterOperations& filters, |
| 30 const gfx::RectF& bounds, | 29 const gfx::RectF& bounds, |
| 31 const gfx::PointF& origin) { | 30 const gfx::PointF& origin) { |
| 32 filters_ = filters; | 31 filters_ = filters; |
| 33 bounds_ = bounds; | 32 bounds_ = bounds; |
| 34 origin_ = origin; | 33 origin_ = origin; |
| 35 } | 34 } |
| 36 | 35 |
| 37 void FilterDisplayItem::Raster(SkCanvas* canvas, | 36 void FilterDisplayItem::Raster(PaintCanvas* canvas, |
| 38 SkPicture::AbortCallback* callback) const { | 37 PaintRecord::AbortCallback* callback) const { |
| 39 canvas->save(); | 38 canvas->save(); |
| 40 canvas->translate(origin_.x(), origin_.y()); | 39 canvas->translate(origin_.x(), origin_.y()); |
| 41 | 40 |
| 42 sk_sp<SkImageFilter> image_filter = RenderSurfaceFilters::BuildImageFilter( | 41 sk_sp<SkImageFilter> image_filter = RenderSurfaceFilters::BuildImageFilter( |
| 43 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); | 42 filters_, gfx::SizeF(bounds_.width(), bounds_.height())); |
| 44 SkRect boundaries = RectFToSkRect(bounds_); | 43 SkRect boundaries = RectFToSkRect(bounds_); |
| 45 boundaries.offset(-origin_.x(), -origin_.y()); | 44 boundaries.offset(-origin_.x(), -origin_.y()); |
| 46 | 45 |
| 47 SkPaint paint; | 46 PaintFlags paint; |
| 48 paint.setBlendMode(SkBlendMode::kSrcOver); | 47 paint.setBlendMode(SkBlendMode::kSrcOver); |
| 49 paint.setImageFilter(std::move(image_filter)); | 48 paint.setImageFilter(std::move(image_filter)); |
| 50 canvas->saveLayer(&boundaries, &paint); | 49 canvas->saveLayer(&boundaries, &paint); |
| 51 | 50 |
| 52 canvas->translate(-origin_.x(), -origin_.y()); | 51 canvas->translate(-origin_.x(), -origin_.y()); |
| 53 } | 52 } |
| 54 | 53 |
| 55 void FilterDisplayItem::AsValueInto( | 54 void FilterDisplayItem::AsValueInto( |
| 56 const gfx::Rect& visual_rect, | 55 const gfx::Rect& visual_rect, |
| 57 base::trace_event::TracedValue* array) const { | 56 base::trace_event::TracedValue* array) const { |
| 58 array->AppendString(base::StringPrintf( | 57 array->AppendString(base::StringPrintf( |
| 59 "FilterDisplayItem bounds: [%s] visualRect: [%s]", | 58 "FilterDisplayItem bounds: [%s] visualRect: [%s]", |
| 60 bounds_.ToString().c_str(), visual_rect.ToString().c_str())); | 59 bounds_.ToString().c_str(), visual_rect.ToString().c_str())); |
| 61 } | 60 } |
| 62 | 61 |
| 63 EndFilterDisplayItem::EndFilterDisplayItem() : DisplayItem(END_FILTER) {} | 62 EndFilterDisplayItem::EndFilterDisplayItem() : DisplayItem(END_FILTER) {} |
| 64 | 63 |
| 65 EndFilterDisplayItem::~EndFilterDisplayItem() {} | 64 EndFilterDisplayItem::~EndFilterDisplayItem() {} |
| 66 | 65 |
| 67 void EndFilterDisplayItem::Raster(SkCanvas* canvas, | 66 void EndFilterDisplayItem::Raster(PaintCanvas* canvas, |
| 68 SkPicture::AbortCallback* callback) const { | 67 PaintRecord::AbortCallback* callback) const { |
| 69 canvas->restore(); | 68 canvas->restore(); |
| 70 canvas->restore(); | 69 canvas->restore(); |
| 71 } | 70 } |
| 72 | 71 |
| 73 void EndFilterDisplayItem::AsValueInto( | 72 void EndFilterDisplayItem::AsValueInto( |
| 74 const gfx::Rect& visual_rect, | 73 const gfx::Rect& visual_rect, |
| 75 base::trace_event::TracedValue* array) const { | 74 base::trace_event::TracedValue* array) const { |
| 76 array->AppendString( | 75 array->AppendString( |
| 77 base::StringPrintf("EndFilterDisplayItem visualRect: [%s]", | 76 base::StringPrintf("EndFilterDisplayItem visualRect: [%s]", |
| 78 visual_rect.ToString().c_str())); | 77 visual_rect.ToString().c_str())); |
| 79 } | 78 } |
| 80 | 79 |
| 81 } // namespace cc | 80 } // namespace cc |
| OLD | NEW |