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