| 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 "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/trace_event/trace_event_argument.h" | 8 #include "base/trace_event/trace_event_argument.h" |
| 9 #include "cc/proto/display_item.pb.h" | 9 #include "cc/proto/display_item.pb.h" |
| 10 #include "cc/proto/skia_conversions.h" | 10 #include "cc/proto/skia_conversions.h" |
| 11 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
| 12 | 12 |
| 13 namespace cc { | 13 namespace cc { |
| 14 | 14 |
| 15 ClipPathDisplayItem::ClipPathDisplayItem(const SkPath& clip_path, | 15 ClipPathDisplayItem::ClipPathDisplayItem() { |
| 16 SkRegion::Op clip_op, | |
| 17 bool antialias) { | |
| 18 SetNew(clip_path, clip_op, antialias); | |
| 19 } | |
| 20 | |
| 21 ClipPathDisplayItem::ClipPathDisplayItem(const proto::DisplayItem& proto) { | |
| 22 DCHECK_EQ(proto::DisplayItem::Type_ClipPath, proto.type()); | |
| 23 | |
| 24 const proto::ClipPathDisplayItem& details = proto.clip_path_item(); | |
| 25 SkRegion::Op clip_op = SkRegionOpFromProto(details.clip_op()); | |
| 26 bool antialias = details.antialias(); | |
| 27 | |
| 28 SkPath clip_path; | |
| 29 if (details.has_clip_path()) { | |
| 30 size_t bytes_read = clip_path.readFromMemory(details.clip_path().data(), | |
| 31 details.clip_path().size()); | |
| 32 DCHECK_EQ(details.clip_path().size(), bytes_read); | |
| 33 } | |
| 34 | |
| 35 SetNew(clip_path, clip_op, antialias); | |
| 36 } | 16 } |
| 37 | 17 |
| 38 ClipPathDisplayItem::~ClipPathDisplayItem() { | 18 ClipPathDisplayItem::~ClipPathDisplayItem() { |
| 39 } | 19 } |
| 40 | 20 |
| 41 void ClipPathDisplayItem::SetNew(const SkPath& clip_path, | 21 void ClipPathDisplayItem::SetNew(const SkPath& clip_path, |
| 42 SkRegion::Op clip_op, | 22 SkRegion::Op clip_op, |
| 43 bool antialias) { | 23 bool antialias) { |
| 44 clip_path_ = clip_path; | 24 clip_path_ = clip_path; |
| 45 clip_op_ = clip_op; | 25 clip_op_ = clip_op; |
| 46 antialias_ = antialias; | 26 antialias_ = antialias; |
| 27 |
| 28 // The size of SkPath's external storage is not currently accounted for (and |
| 29 // may well be shared anyway). |
| 30 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 1 /* op_count */, |
| 31 0 /* external_memory_usage */); |
| 47 } | 32 } |
| 48 | 33 |
| 49 void ClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 34 void ClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
| 50 proto->set_type(proto::DisplayItem::Type_ClipPath); | 35 proto->set_type(proto::DisplayItem::Type_ClipPath); |
| 51 | 36 |
| 52 proto::ClipPathDisplayItem* details = proto->mutable_clip_path_item(); | 37 proto::ClipPathDisplayItem* details = proto->mutable_clip_path_item(); |
| 53 details->set_clip_op(SkRegionOpToProto(clip_op_)); | 38 details->set_clip_op(SkRegionOpToProto(clip_op_)); |
| 54 details->set_antialias(antialias_); | 39 details->set_antialias(antialias_); |
| 55 | 40 |
| 56 // Just use skia's serialization method for the SkPath for now. | 41 // Just use skia's serialization method for the SkPath for now. |
| 57 size_t path_size = clip_path_.writeToMemory(nullptr); | 42 size_t path_size = clip_path_.writeToMemory(nullptr); |
| 58 if (path_size > 0) { | 43 if (path_size > 0) { |
| 59 scoped_ptr<uint8_t[]> buffer(new uint8_t[path_size]); | 44 scoped_ptr<uint8_t[]> buffer(new uint8_t[path_size]); |
| 60 clip_path_.writeToMemory(buffer.get()); | 45 clip_path_.writeToMemory(buffer.get()); |
| 61 details->set_clip_path(buffer.get(), path_size); | 46 details->set_clip_path(buffer.get(), path_size); |
| 62 } | 47 } |
| 63 } | 48 } |
| 64 | 49 |
| 50 void ClipPathDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { |
| 51 DCHECK_EQ(proto::DisplayItem::Type_ClipPath, proto.type()); |
| 52 |
| 53 const proto::ClipPathDisplayItem& details = proto.clip_path_item(); |
| 54 SkRegion::Op clip_op = SkRegionOpFromProto(details.clip_op()); |
| 55 bool antialias = details.antialias(); |
| 56 |
| 57 SkPath clip_path; |
| 58 if (details.has_clip_path()) { |
| 59 size_t bytes_read = clip_path.readFromMemory(details.clip_path().data(), |
| 60 details.clip_path().size()); |
| 61 DCHECK_EQ(details.clip_path().size(), bytes_read); |
| 62 } |
| 63 |
| 64 SetNew(clip_path, clip_op, antialias); |
| 65 } |
| 66 |
| 65 void ClipPathDisplayItem::Raster(SkCanvas* canvas, | 67 void ClipPathDisplayItem::Raster(SkCanvas* canvas, |
| 66 const gfx::Rect& canvas_target_playback_rect, | 68 const gfx::Rect& canvas_target_playback_rect, |
| 67 SkPicture::AbortCallback* callback) const { | 69 SkPicture::AbortCallback* callback) const { |
| 68 canvas->save(); | 70 canvas->save(); |
| 69 canvas->clipPath(clip_path_, clip_op_, antialias_); | 71 canvas->clipPath(clip_path_, clip_op_, antialias_); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void ClipPathDisplayItem::AsValueInto( | 74 void ClipPathDisplayItem::AsValueInto( |
| 73 const gfx::Rect& visual_rect, | 75 const gfx::Rect& visual_rect, |
| 74 base::trace_event::TracedValue* array) const { | 76 base::trace_event::TracedValue* array) const { |
| 75 array->AppendString(base::StringPrintf( | 77 array->AppendString(base::StringPrintf( |
| 76 "ClipPathDisplayItem length: %d visualRect: [%s]", | 78 "ClipPathDisplayItem length: %d visualRect: [%s]", |
| 77 clip_path_.countPoints(), visual_rect.ToString().c_str())); | 79 clip_path_.countPoints(), visual_rect.ToString().c_str())); |
| 78 } | 80 } |
| 79 | 81 |
| 80 size_t ClipPathDisplayItem::ExternalMemoryUsage() const { | 82 EndClipPathDisplayItem::EndClipPathDisplayItem() { |
| 81 // The size of SkPath's external storage is not currently accounted for (and | 83 DisplayItem::SetNew(true /* suitable_for_gpu_raster */, 0 /* op_count */, |
| 82 // may well be shared anyway). | 84 0 /* external_memory_usage */); |
| 83 return 0; | |
| 84 } | |
| 85 | |
| 86 EndClipPathDisplayItem::EndClipPathDisplayItem() {} | |
| 87 | |
| 88 EndClipPathDisplayItem::EndClipPathDisplayItem( | |
| 89 const proto::DisplayItem& proto) { | |
| 90 DCHECK_EQ(proto::DisplayItem::Type_EndClipPath, proto.type()); | |
| 91 } | 85 } |
| 92 | 86 |
| 93 EndClipPathDisplayItem::~EndClipPathDisplayItem() { | 87 EndClipPathDisplayItem::~EndClipPathDisplayItem() { |
| 94 } | 88 } |
| 95 | 89 |
| 96 void EndClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 90 void EndClipPathDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
| 97 proto->set_type(proto::DisplayItem::Type_EndClipPath); | 91 proto->set_type(proto::DisplayItem::Type_EndClipPath); |
| 98 } | 92 } |
| 99 | 93 |
| 94 void EndClipPathDisplayItem::FromProtobuf(const proto::DisplayItem& proto) { |
| 95 DCHECK_EQ(proto::DisplayItem::Type_EndClipPath, proto.type()); |
| 96 } |
| 97 |
| 100 void EndClipPathDisplayItem::Raster( | 98 void EndClipPathDisplayItem::Raster( |
| 101 SkCanvas* canvas, | 99 SkCanvas* canvas, |
| 102 const gfx::Rect& canvas_target_playback_rect, | 100 const gfx::Rect& canvas_target_playback_rect, |
| 103 SkPicture::AbortCallback* callback) const { | 101 SkPicture::AbortCallback* callback) const { |
| 104 canvas->restore(); | 102 canvas->restore(); |
| 105 } | 103 } |
| 106 | 104 |
| 107 void EndClipPathDisplayItem::AsValueInto( | 105 void EndClipPathDisplayItem::AsValueInto( |
| 108 const gfx::Rect& visual_rect, | 106 const gfx::Rect& visual_rect, |
| 109 base::trace_event::TracedValue* array) const { | 107 base::trace_event::TracedValue* array) const { |
| 110 array->AppendString( | 108 array->AppendString( |
| 111 base::StringPrintf("EndClipPathDisplayItem visualRect: [%s]", | 109 base::StringPrintf("EndClipPathDisplayItem visualRect: [%s]", |
| 112 visual_rect.ToString().c_str())); | 110 visual_rect.ToString().c_str())); |
| 113 } | 111 } |
| 114 | 112 |
| 115 size_t EndClipPathDisplayItem::ExternalMemoryUsage() const { | |
| 116 return 0; | |
| 117 } | |
| 118 | |
| 119 } // namespace cc | 113 } // namespace cc |
| OLD | NEW |