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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/trace_event/trace_event_argument.h" | 10 #include "base/trace_event/trace_event_argument.h" |
11 #include "cc/debug/picture_debug_util.h" | 11 #include "cc/debug/picture_debug_util.h" |
12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
13 #include "third_party/skia/include/core/SkMatrix.h" | 13 #include "third_party/skia/include/core/SkMatrix.h" |
14 #include "third_party/skia/include/core/SkPicture.h" | 14 #include "third_party/skia/include/core/SkPicture.h" |
15 #include "third_party/skia/include/utils/SkPictureUtils.h" | 15 #include "third_party/skia/include/utils/SkPictureUtils.h" |
| 16 #include "ui/gfx/skia_util.h" |
16 | 17 |
17 namespace cc { | 18 namespace cc { |
18 | 19 |
19 DrawingDisplayItem::DrawingDisplayItem() { | 20 DrawingDisplayItem::DrawingDisplayItem() { |
20 } | 21 } |
21 | 22 |
22 DrawingDisplayItem::~DrawingDisplayItem() { | 23 DrawingDisplayItem::~DrawingDisplayItem() { |
23 } | 24 } |
24 | 25 |
25 void DrawingDisplayItem::SetNew(skia::RefPtr<SkPicture> picture) { | 26 void DrawingDisplayItem::SetNew(skia::RefPtr<SkPicture> picture) { |
26 picture_ = picture.Pass(); | 27 picture_ = picture.Pass(); |
27 DisplayItem::SetNew(picture_->suitableForGpuRasterization(NULL), | 28 DisplayItem::SetNew(picture_->suitableForGpuRasterization(NULL), |
28 picture_->approximateOpCount(), | 29 picture_->approximateOpCount(), |
29 SkPictureUtils::ApproximateBytesUsed(picture_.get())); | 30 SkPictureUtils::ApproximateBytesUsed(picture_.get())); |
30 } | 31 } |
31 | 32 |
32 void DrawingDisplayItem::Raster(SkCanvas* canvas, | 33 void DrawingDisplayItem::Raster(SkCanvas* canvas, |
| 34 const gfx::Rect& canvas_target_playback_rect, |
33 SkPicture::AbortCallback* callback) const { | 35 SkPicture::AbortCallback* callback) const { |
| 36 // The canvas_playback_rect can be empty to signify no culling is desired. |
| 37 if (!canvas_target_playback_rect.IsEmpty()) { |
| 38 const SkMatrix& matrix = canvas->getTotalMatrix(); |
| 39 const SkRect& cull_rect = picture_->cullRect(); |
| 40 SkRect target_rect; |
| 41 matrix.mapRect(&target_rect, cull_rect); |
| 42 if (!target_rect.intersect(gfx::RectToSkRect(canvas_target_playback_rect))) |
| 43 return; |
| 44 } |
| 45 |
34 // SkPicture always does a wrapping save/restore on the canvas, so it is not | 46 // SkPicture always does a wrapping save/restore on the canvas, so it is not |
35 // necessary here. | 47 // necessary here. |
36 if (callback) | 48 if (callback) |
37 picture_->playback(canvas, callback); | 49 picture_->playback(canvas, callback); |
38 else | 50 else |
39 canvas->drawPicture(picture_.get()); | 51 canvas->drawPicture(picture_.get()); |
40 } | 52 } |
41 | 53 |
42 void DrawingDisplayItem::AsValueInto( | 54 void DrawingDisplayItem::AsValueInto( |
43 base::trace_event::TracedValue* array) const { | 55 base::trace_event::TracedValue* array) const { |
44 array->BeginDictionary(); | 56 array->BeginDictionary(); |
45 array->SetString("name", "DrawingDisplayItem"); | 57 array->SetString("name", "DrawingDisplayItem"); |
46 array->SetString( | 58 array->SetString( |
47 "cullRect", | 59 "cullRect", |
48 base::StringPrintf("[%f,%f,%f,%f]", picture_->cullRect().x(), | 60 base::StringPrintf("[%f,%f,%f,%f]", picture_->cullRect().x(), |
49 picture_->cullRect().y(), picture_->cullRect().width(), | 61 picture_->cullRect().y(), picture_->cullRect().width(), |
50 picture_->cullRect().height())); | 62 picture_->cullRect().height())); |
51 std::string b64_picture; | 63 std::string b64_picture; |
52 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); | 64 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); |
53 array->SetString("skp64", b64_picture); | 65 array->SetString("skp64", b64_picture); |
54 array->EndDictionary(); | 66 array->EndDictionary(); |
55 } | 67 } |
56 | 68 |
57 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const { | 69 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const { |
58 item->SetNew(picture_); | 70 item->SetNew(picture_); |
59 } | 71 } |
60 | 72 |
61 } // namespace cc | 73 } // namespace cc |
OLD | NEW |