| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_path_display_item.h" | 5 #include "cc/playback/clip_path_display_item.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/trace_event/trace_event_argument.h" | 11 #include "base/trace_event/trace_event_argument.h" |
| 12 #include "cc/proto/display_item.pb.h" | 12 #include "cc/proto/display_item.pb.h" |
| 13 #include "cc/proto/skia_conversions.h" | 13 #include "cc/proto/skia_conversions.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 | 17 |
| 18 ClipPathDisplayItem::ClipPathDisplayItem(const SkPath& clip_path, | 18 ClipPathDisplayItem::ClipPathDisplayItem(const SkPath& clip_path, |
| 19 SkClipOp clip_op, | |
| 20 bool antialias) | 19 bool antialias) |
| 21 : DisplayItem(CLIP_PATH) { | 20 : DisplayItem(CLIP_PATH) { |
| 22 SetNew(clip_path, clip_op, antialias); | 21 SetNew(clip_path, antialias); |
| 23 } | 22 } |
| 24 | 23 |
| 25 ClipPathDisplayItem::ClipPathDisplayItem(const proto::DisplayItem& proto) | 24 ClipPathDisplayItem::ClipPathDisplayItem(const proto::DisplayItem& proto) |
| 26 : DisplayItem(CLIP_PATH) { | 25 : DisplayItem(CLIP_PATH) { |
| 27 DCHECK_EQ(proto::DisplayItem::Type_ClipPath, proto.type()); | 26 DCHECK_EQ(proto::DisplayItem::Type_ClipPath, proto.type()); |
| 28 | 27 |
| 29 const proto::ClipPathDisplayItem& details = proto.clip_path_item(); | 28 const proto::ClipPathDisplayItem& details = proto.clip_path_item(); |
| 30 SkClipOp clip_op = SkClipOpFromProto(details.clip_op()); | |
| 31 bool antialias = details.antialias(); | 29 bool antialias = details.antialias(); |
| 32 | 30 |
| 33 SkPath clip_path; | 31 SkPath clip_path; |
| 34 if (details.has_clip_path()) { | 32 if (details.has_clip_path()) { |
| 35 size_t bytes_read = clip_path.readFromMemory(details.clip_path().data(), | 33 size_t bytes_read = clip_path.readFromMemory(details.clip_path().data(), |
| 36 details.clip_path().size()); | 34 details.clip_path().size()); |
| 37 DCHECK_EQ(details.clip_path().size(), bytes_read); | 35 DCHECK_EQ(details.clip_path().size(), bytes_read); |
| 38 } | 36 } |
| 39 | 37 |
| 40 SetNew(clip_path, clip_op, antialias); | 38 SetNew(clip_path, antialias); |
| 41 } | 39 } |
| 42 | 40 |
| 43 ClipPathDisplayItem::~ClipPathDisplayItem() { | 41 ClipPathDisplayItem::~ClipPathDisplayItem() { |
| 44 } | 42 } |
| 45 | 43 |
| 46 void ClipPathDisplayItem::SetNew(const SkPath& clip_path, | 44 void ClipPathDisplayItem::SetNew(const SkPath& clip_path, |
| 47 SkClipOp clip_op, | |
| 48 bool antialias) { | 45 bool antialias) { |
| 49 clip_path_ = clip_path; | 46 clip_path_ = clip_path; |
| 50 clip_op_ = clip_op; | |
| 51 antialias_ = antialias; | 47 antialias_ = antialias; |
| 52 } | 48 } |
| 53 | 49 |
| 54 void ClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 50 void ClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
| 55 proto->set_type(proto::DisplayItem::Type_ClipPath); | 51 proto->set_type(proto::DisplayItem::Type_ClipPath); |
| 56 | 52 |
| 57 proto::ClipPathDisplayItem* details = proto->mutable_clip_path_item(); | 53 proto::ClipPathDisplayItem* details = proto->mutable_clip_path_item(); |
| 58 details->set_clip_op(SkClipOpToProto(clip_op_)); | |
| 59 details->set_antialias(antialias_); | 54 details->set_antialias(antialias_); |
| 60 | 55 |
| 61 // Just use skia's serialization method for the SkPath for now. | 56 // Just use skia's serialization method for the SkPath for now. |
| 62 size_t path_size = clip_path_.writeToMemory(nullptr); | 57 size_t path_size = clip_path_.writeToMemory(nullptr); |
| 63 if (path_size > 0) { | 58 if (path_size > 0) { |
| 64 std::unique_ptr<uint8_t[]> buffer(new uint8_t[path_size]); | 59 std::unique_ptr<uint8_t[]> buffer(new uint8_t[path_size]); |
| 65 clip_path_.writeToMemory(buffer.get()); | 60 clip_path_.writeToMemory(buffer.get()); |
| 66 details->set_clip_path(buffer.get(), path_size); | 61 details->set_clip_path(buffer.get(), path_size); |
| 67 } | 62 } |
| 68 } | 63 } |
| 69 | 64 |
| 70 void ClipPathDisplayItem::Raster(SkCanvas* canvas, | 65 void ClipPathDisplayItem::Raster(SkCanvas* canvas, |
| 71 SkPicture::AbortCallback* callback) const { | 66 SkPicture::AbortCallback* callback) const { |
| 72 canvas->save(); | 67 canvas->save(); |
| 73 canvas->clipPath(clip_path_, clip_op_, antialias_); | 68 canvas->clipPath(clip_path_, antialias_); |
| 74 } | 69 } |
| 75 | 70 |
| 76 void ClipPathDisplayItem::AsValueInto( | 71 void ClipPathDisplayItem::AsValueInto( |
| 77 const gfx::Rect& visual_rect, | 72 const gfx::Rect& visual_rect, |
| 78 base::trace_event::TracedValue* array) const { | 73 base::trace_event::TracedValue* array) const { |
| 79 array->AppendString(base::StringPrintf( | 74 array->AppendString(base::StringPrintf( |
| 80 "ClipPathDisplayItem length: %d visualRect: [%s]", | 75 "ClipPathDisplayItem length: %d visualRect: [%s]", |
| 81 clip_path_.countPoints(), visual_rect.ToString().c_str())); | 76 clip_path_.countPoints(), visual_rect.ToString().c_str())); |
| 82 } | 77 } |
| 83 | 78 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 103 | 98 |
| 104 void EndClipPathDisplayItem::AsValueInto( | 99 void EndClipPathDisplayItem::AsValueInto( |
| 105 const gfx::Rect& visual_rect, | 100 const gfx::Rect& visual_rect, |
| 106 base::trace_event::TracedValue* array) const { | 101 base::trace_event::TracedValue* array) const { |
| 107 array->AppendString( | 102 array->AppendString( |
| 108 base::StringPrintf("EndClipPathDisplayItem visualRect: [%s]", | 103 base::StringPrintf("EndClipPathDisplayItem visualRect: [%s]", |
| 109 visual_rect.ToString().c_str())); | 104 visual_rect.ToString().c_str())); |
| 110 } | 105 } |
| 111 | 106 |
| 112 } // namespace cc | 107 } // namespace cc |
| OLD | NEW |