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/drawing_display_item.h" | 5 #include "cc/playback/drawing_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/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "cc/debug/picture_debug_util.h" | 15 #include "cc/debug/picture_debug_util.h" |
16 #include "third_party/skia/include/core/SkCanvas.h" | |
17 #include "third_party/skia/include/core/SkData.h" | 16 #include "third_party/skia/include/core/SkData.h" |
18 #include "third_party/skia/include/core/SkMatrix.h" | 17 #include "third_party/skia/include/core/SkMatrix.h" |
19 #include "third_party/skia/include/core/SkPicture.h" | |
20 #include "third_party/skia/include/core/SkStream.h" | 18 #include "third_party/skia/include/core/SkStream.h" |
21 #include "third_party/skia/include/utils/SkPictureUtils.h" | |
22 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
23 | 20 |
24 namespace cc { | 21 namespace cc { |
25 | 22 |
26 DrawingDisplayItem::DrawingDisplayItem() : DisplayItem(DRAWING) {} | 23 DrawingDisplayItem::DrawingDisplayItem() : DisplayItem(DRAWING) {} |
27 | 24 |
28 DrawingDisplayItem::DrawingDisplayItem(sk_sp<const SkPicture> picture) | 25 DrawingDisplayItem::DrawingDisplayItem(sk_sp<const PaintRecord> picture) |
29 : DisplayItem(DRAWING) { | 26 : DisplayItem(DRAWING) { |
30 SetNew(std::move(picture)); | 27 SetNew(std::move(picture)); |
31 } | 28 } |
32 | 29 |
33 DrawingDisplayItem::DrawingDisplayItem(const DrawingDisplayItem& item) | 30 DrawingDisplayItem::DrawingDisplayItem(const DrawingDisplayItem& item) |
34 : DisplayItem(DRAWING) { | 31 : DisplayItem(DRAWING) { |
35 item.CloneTo(this); | 32 item.CloneTo(this); |
36 } | 33 } |
37 | 34 |
38 DrawingDisplayItem::~DrawingDisplayItem() { | 35 DrawingDisplayItem::~DrawingDisplayItem() { |
39 } | 36 } |
40 | 37 |
41 void DrawingDisplayItem::SetNew(sk_sp<const SkPicture> picture) { | 38 void DrawingDisplayItem::SetNew(sk_sp<const PaintRecord> picture) { |
42 picture_ = std::move(picture); | 39 picture_ = std::move(picture); |
43 } | 40 } |
44 | 41 |
45 sk_sp<const SkPicture> DrawingDisplayItem::GetPicture() const { | 42 sk_sp<const PaintRecord> DrawingDisplayItem::GetPicture() const { |
46 return picture_; | 43 return picture_; |
47 } | 44 } |
48 | 45 |
49 DISABLE_CFI_PERF | 46 DISABLE_CFI_PERF |
50 void DrawingDisplayItem::Raster(SkCanvas* canvas, | 47 void DrawingDisplayItem::Raster(PaintCanvas* canvas, |
51 SkPicture::AbortCallback* callback) const { | 48 PaintRecord::AbortCallback* callback) const { |
52 if (canvas->quickReject(picture_->cullRect())) | 49 if (canvas->quickReject(picture_->cullRect())) |
53 return; | 50 return; |
54 | 51 |
55 // SkPicture always does a wrapping save/restore on the canvas, so it is not | 52 // PaintRecord always does a wrapping save/restore on the canvas, so it is not |
56 // necessary here. | 53 // necessary here. |
57 if (callback) | 54 if (callback) |
58 picture_->playback(canvas, callback); | 55 picture_->playback(canvas, callback); |
59 else | 56 else |
60 canvas->drawPicture(picture_.get()); | 57 canvas->drawPicture(picture_.get()); |
61 } | 58 } |
62 | 59 |
63 void DrawingDisplayItem::AsValueInto( | 60 void DrawingDisplayItem::AsValueInto( |
64 const gfx::Rect& visual_rect, | 61 const gfx::Rect& visual_rect, |
65 base::trace_event::TracedValue* array) const { | 62 base::trace_event::TracedValue* array) const { |
66 array->BeginDictionary(); | 63 array->BeginDictionary(); |
67 array->SetString("name", "DrawingDisplayItem"); | 64 array->SetString("name", "DrawingDisplayItem"); |
68 | 65 |
69 array->BeginArray("visualRect"); | 66 array->BeginArray("visualRect"); |
70 array->AppendInteger(visual_rect.x()); | 67 array->AppendInteger(visual_rect.x()); |
71 array->AppendInteger(visual_rect.y()); | 68 array->AppendInteger(visual_rect.y()); |
72 array->AppendInteger(visual_rect.width()); | 69 array->AppendInteger(visual_rect.width()); |
73 array->AppendInteger(visual_rect.height()); | 70 array->AppendInteger(visual_rect.height()); |
74 array->EndArray(); | 71 array->EndArray(); |
75 | 72 |
76 array->BeginArray("cullRect"); | 73 array->BeginArray("cullRect"); |
77 array->AppendInteger(picture_->cullRect().x()); | 74 array->AppendInteger(picture_->cullRect().x()); |
78 array->AppendInteger(picture_->cullRect().y()); | 75 array->AppendInteger(picture_->cullRect().y()); |
79 array->AppendInteger(picture_->cullRect().width()); | 76 array->AppendInteger(picture_->cullRect().width()); |
80 array->AppendInteger(picture_->cullRect().height()); | 77 array->AppendInteger(picture_->cullRect().height()); |
81 array->EndArray(); | 78 array->EndArray(); |
82 | 79 |
83 std::string b64_picture; | 80 std::string b64_picture; |
84 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); | 81 PictureDebugUtil::SerializeAsBase64(ToSkPicture(picture_.get()), |
| 82 &b64_picture); |
85 array->SetString("skp64", b64_picture); | 83 array->SetString("skp64", b64_picture); |
86 array->EndDictionary(); | 84 array->EndDictionary(); |
87 } | 85 } |
88 | 86 |
89 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const { | 87 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const { |
90 item->SetNew(picture_); | 88 item->SetNew(picture_); |
91 } | 89 } |
92 | 90 |
93 size_t DrawingDisplayItem::ExternalMemoryUsage() const { | 91 size_t DrawingDisplayItem::ExternalMemoryUsage() const { |
94 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); | 92 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); |
95 } | 93 } |
96 | 94 |
97 DISABLE_CFI_PERF | 95 DISABLE_CFI_PERF |
98 int DrawingDisplayItem::ApproximateOpCount() const { | 96 int DrawingDisplayItem::ApproximateOpCount() const { |
99 return picture_->approximateOpCount(); | 97 return picture_->approximateOpCount(); |
100 } | 98 } |
101 | 99 |
102 } // namespace cc | 100 } // namespace cc |
OLD | NEW |