| 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/clip_display_item.h" | 5 #include "cc/playback/clip_display_item.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
| 14 #include "cc/proto/display_item.pb.h" | 14 #include "cc/proto/display_item.pb.h" |
| 15 #include "cc/proto/gfx_conversions.h" | 15 #include "cc/proto/gfx_conversions.h" |
| 16 #include "cc/proto/skia_conversions.h" | 16 #include "cc/proto/skia_conversions.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
| 18 #include "ui/gfx/skia_util.h" | 18 #include "ui/gfx/skia_util.h" |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 class ImageSerializationProcessor; | 21 class ImageSerializationProcessor; |
| 22 | 22 |
| 23 ClipDisplayItem::ClipDisplayItem( | 23 ClipDisplayItem::ClipDisplayItem(const gfx::Rect& clip_rect, |
| 24 const gfx::Rect& clip_rect, | 24 const std::vector<SkRRect>& rounded_clip_rects, |
| 25 const std::vector<SkRRect>& rounded_clip_rects) { | 25 bool antialias) { |
| 26 SetNew(clip_rect, rounded_clip_rects); | 26 SetNew(clip_rect, rounded_clip_rects, antialias); |
| 27 } | 27 } |
| 28 | 28 |
| 29 ClipDisplayItem::ClipDisplayItem(const proto::DisplayItem& proto) { | 29 ClipDisplayItem::ClipDisplayItem(const proto::DisplayItem& proto) { |
| 30 DCHECK_EQ(proto::DisplayItem::Type_Clip, proto.type()); | 30 DCHECK_EQ(proto::DisplayItem::Type_Clip, proto.type()); |
| 31 | 31 |
| 32 const proto::ClipDisplayItem& details = proto.clip_item(); | 32 const proto::ClipDisplayItem& details = proto.clip_item(); |
| 33 gfx::Rect clip_rect = ProtoToRect(details.clip_rect()); | 33 gfx::Rect clip_rect = ProtoToRect(details.clip_rect()); |
| 34 std::vector<SkRRect> rounded_clip_rects; | 34 std::vector<SkRRect> rounded_clip_rects; |
| 35 rounded_clip_rects.reserve(details.rounded_rects_size()); | 35 rounded_clip_rects.reserve(details.rounded_rects_size()); |
| 36 for (int i = 0; i < details.rounded_rects_size(); i++) { | 36 for (int i = 0; i < details.rounded_rects_size(); i++) { |
| 37 rounded_clip_rects.push_back(ProtoToSkRRect(details.rounded_rects(i))); | 37 rounded_clip_rects.push_back(ProtoToSkRRect(details.rounded_rects(i))); |
| 38 } | 38 } |
| 39 SetNew(clip_rect, rounded_clip_rects); | 39 bool antialias = details.antialias(); |
| 40 SetNew(clip_rect, rounded_clip_rects, antialias); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void ClipDisplayItem::SetNew(const gfx::Rect& clip_rect, | 43 void ClipDisplayItem::SetNew(const gfx::Rect& clip_rect, |
| 43 const std::vector<SkRRect>& rounded_clip_rects) { | 44 const std::vector<SkRRect>& rounded_clip_rects, |
| 45 bool antialias) { |
| 44 clip_rect_ = clip_rect; | 46 clip_rect_ = clip_rect; |
| 45 rounded_clip_rects_ = rounded_clip_rects; | 47 rounded_clip_rects_ = rounded_clip_rects; |
| 48 antialias_ = antialias; |
| 46 } | 49 } |
| 47 | 50 |
| 48 ClipDisplayItem::~ClipDisplayItem() {} | 51 ClipDisplayItem::~ClipDisplayItem() {} |
| 49 | 52 |
| 50 void ClipDisplayItem::ToProtobuf( | 53 void ClipDisplayItem::ToProtobuf( |
| 51 proto::DisplayItem* proto, | 54 proto::DisplayItem* proto, |
| 52 ImageSerializationProcessor* image_serialization_processor) const { | 55 ImageSerializationProcessor* image_serialization_processor) const { |
| 53 proto->set_type(proto::DisplayItem::Type_Clip); | 56 proto->set_type(proto::DisplayItem::Type_Clip); |
| 54 | 57 |
| 55 proto::ClipDisplayItem* details = proto->mutable_clip_item(); | 58 proto::ClipDisplayItem* details = proto->mutable_clip_item(); |
| 56 RectToProto(clip_rect_, details->mutable_clip_rect()); | 59 RectToProto(clip_rect_, details->mutable_clip_rect()); |
| 57 DCHECK_EQ(0, details->rounded_rects_size()); | 60 DCHECK_EQ(0, details->rounded_rects_size()); |
| 58 for (const auto& rrect : rounded_clip_rects_) { | 61 for (const auto& rrect : rounded_clip_rects_) { |
| 59 SkRRectToProto(rrect, details->add_rounded_rects()); | 62 SkRRectToProto(rrect, details->add_rounded_rects()); |
| 60 } | 63 } |
| 64 details->set_antialias(antialias_); |
| 61 } | 65 } |
| 62 | 66 |
| 63 void ClipDisplayItem::Raster(SkCanvas* canvas, | 67 void ClipDisplayItem::Raster(SkCanvas* canvas, |
| 64 const gfx::Rect& canvas_target_playback_rect, | 68 const gfx::Rect& canvas_target_playback_rect, |
| 65 SkPicture::AbortCallback* callback) const { | 69 SkPicture::AbortCallback* callback) const { |
| 66 bool antialiased = true; | |
| 67 canvas->save(); | 70 canvas->save(); |
| 68 canvas->clipRect(SkRect::MakeXYWH(clip_rect_.x(), clip_rect_.y(), | 71 canvas->clipRect(SkRect::MakeXYWH(clip_rect_.x(), clip_rect_.y(), |
| 69 clip_rect_.width(), clip_rect_.height()), | 72 clip_rect_.width(), clip_rect_.height()), |
| 70 SkRegion::kIntersect_Op, antialiased); | 73 SkRegion::kIntersect_Op, antialias_); |
| 71 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) { | 74 for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) { |
| 72 if (rounded_clip_rects_[i].isRect()) { | 75 if (rounded_clip_rects_[i].isRect()) { |
| 73 canvas->clipRect(rounded_clip_rects_[i].rect(), SkRegion::kIntersect_Op, | 76 canvas->clipRect(rounded_clip_rects_[i].rect(), SkRegion::kIntersect_Op, |
| 74 antialiased); | 77 antialias_); |
| 75 } else { | 78 } else { |
| 76 canvas->clipRRect(rounded_clip_rects_[i], SkRegion::kIntersect_Op, | 79 canvas->clipRRect(rounded_clip_rects_[i], SkRegion::kIntersect_Op, |
| 77 antialiased); | 80 antialias_); |
| 78 } | 81 } |
| 79 } | 82 } |
| 80 } | 83 } |
| 81 | 84 |
| 82 void ClipDisplayItem::AsValueInto(const gfx::Rect& visual_rect, | 85 void ClipDisplayItem::AsValueInto(const gfx::Rect& visual_rect, |
| 83 base::trace_event::TracedValue* array) const { | 86 base::trace_event::TracedValue* array) const { |
| 84 std::string value = base::StringPrintf( | 87 std::string value = base::StringPrintf( |
| 85 "ClipDisplayItem rect: [%s] visualRect: [%s]", | 88 "ClipDisplayItem rect: [%s] visualRect: [%s]", |
| 86 clip_rect_.ToString().c_str(), visual_rect.ToString().c_str()); | 89 clip_rect_.ToString().c_str(), visual_rect.ToString().c_str()); |
| 87 for (const SkRRect& rounded_rect : rounded_clip_rects_) { | 90 for (const SkRRect& rounded_rect : rounded_clip_rects_) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 base::trace_event::TracedValue* array) const { | 140 base::trace_event::TracedValue* array) const { |
| 138 array->AppendString(base::StringPrintf("EndClipDisplayItem visualRect: [%s]", | 141 array->AppendString(base::StringPrintf("EndClipDisplayItem visualRect: [%s]", |
| 139 visual_rect.ToString().c_str())); | 142 visual_rect.ToString().c_str())); |
| 140 } | 143 } |
| 141 | 144 |
| 142 size_t EndClipDisplayItem::ExternalMemoryUsage() const { | 145 size_t EndClipDisplayItem::ExternalMemoryUsage() const { |
| 143 return 0; | 146 return 0; |
| 144 } | 147 } |
| 145 | 148 |
| 146 } // namespace cc | 149 } // namespace cc |
| OLD | NEW |