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/resources/drawing_display_item.h" | 5 #include "cc/resources/drawing_display_item.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
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/debug/picture_debug_util.h" | 12 #include "cc/debug/picture_debug_util.h" |
13 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
14 #include "third_party/skia/include/core/SkDrawPictureCallback.h" | 14 #include "third_party/skia/include/core/SkDrawPictureCallback.h" |
15 #include "third_party/skia/include/core/SkMatrix.h" | 15 #include "third_party/skia/include/core/SkMatrix.h" |
16 #include "third_party/skia/include/core/SkPicture.h" | 16 #include "third_party/skia/include/core/SkPicture.h" |
17 #include "third_party/skia/include/utils/SkPictureUtils.h" | 17 #include "third_party/skia/include/utils/SkPictureUtils.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 | 20 |
21 DrawingDisplayItem::DrawingDisplayItem(skia::RefPtr<SkPicture> picture) | 21 DrawingDisplayItem::DrawingDisplayItem(skia::RefPtr<SkPicture> picture, |
22 : picture_(picture) { | 22 gfx::PointF location) |
| 23 : picture_(picture), location_(location) { |
23 } | 24 } |
24 | 25 |
25 DrawingDisplayItem::~DrawingDisplayItem() { | 26 DrawingDisplayItem::~DrawingDisplayItem() { |
26 } | 27 } |
27 | 28 |
28 void DrawingDisplayItem::Raster(SkCanvas* canvas, | 29 void DrawingDisplayItem::Raster(SkCanvas* canvas, |
29 SkDrawPictureCallback* callback) const { | 30 SkDrawPictureCallback* callback) const { |
30 canvas->save(); | 31 canvas->save(); |
| 32 canvas->translate(location_.x(), location_.y()); |
31 if (callback) | 33 if (callback) |
32 picture_->playback(canvas, callback); | 34 picture_->playback(canvas, callback); |
33 else | 35 else |
34 canvas->drawPicture(picture_.get()); | 36 canvas->drawPicture(picture_.get()); |
35 canvas->restore(); | 37 canvas->restore(); |
36 } | 38 } |
37 | 39 |
38 void DrawingDisplayItem::RasterForTracing(SkCanvas* canvas) const { | 40 void DrawingDisplayItem::RasterForTracing(SkCanvas* canvas) const { |
39 canvas->save(); | 41 canvas->save(); |
| 42 canvas->translate(location_.x(), location_.y()); |
40 // The picture debugger in about:tracing doesn't drill down into |drawPicture| | 43 // The picture debugger in about:tracing doesn't drill down into |drawPicture| |
41 // operations. Calling |playback()| rather than |drawPicture()| causes the | 44 // operations. Calling |playback()| rather than |drawPicture()| causes the |
42 // skia operations in |picture_| to appear individually in the picture | 45 // skia operations in |picture_| to appear individually in the picture |
43 // produced for tracing rather than being hidden inside a drawPicture | 46 // produced for tracing rather than being hidden inside a drawPicture |
44 // operation. | 47 // operation. |
45 picture_->playback(canvas); | 48 picture_->playback(canvas); |
46 canvas->restore(); | 49 canvas->restore(); |
47 } | 50 } |
48 | 51 |
49 bool DrawingDisplayItem::IsSuitableForGpuRasterization() const { | 52 bool DrawingDisplayItem::IsSuitableForGpuRasterization() const { |
50 return picture_->suitableForGpuRasterization(NULL); | 53 return picture_->suitableForGpuRasterization(NULL); |
51 } | 54 } |
52 | 55 |
53 int DrawingDisplayItem::ApproximateOpCount() const { | 56 int DrawingDisplayItem::ApproximateOpCount() const { |
54 return picture_->approximateOpCount(); | 57 return picture_->approximateOpCount() + sizeof(gfx::PointF); |
55 } | 58 } |
56 | 59 |
57 size_t DrawingDisplayItem::PictureMemoryUsage() const { | 60 size_t DrawingDisplayItem::PictureMemoryUsage() const { |
58 DCHECK(picture_); | 61 DCHECK(picture_); |
59 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); | 62 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); |
60 } | 63 } |
61 | 64 |
62 void DrawingDisplayItem::AsValueInto( | 65 void DrawingDisplayItem::AsValueInto( |
63 base::trace_event::TracedValue* array) const { | 66 base::trace_event::TracedValue* array) const { |
64 array->BeginDictionary(); | 67 array->BeginDictionary(); |
65 array->SetString("name", "DrawingDisplayItem"); | 68 array->SetString("name", "DrawingDisplayItem"); |
66 array->SetString( | 69 array->SetString("location", |
67 "cullRect", | 70 base::StringPrintf("[%f,%f]", picture_->cullRect().x(), |
68 base::StringPrintf("[%f,%f,%f,%f]", picture_->cullRect().x(), | 71 picture_->cullRect().y())); |
69 picture_->cullRect().y(), picture_->cullRect().width(), | |
70 picture_->cullRect().height())); | |
71 std::string b64_picture; | 72 std::string b64_picture; |
72 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); | 73 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); |
73 array->SetString("skp64", b64_picture); | 74 array->SetString("skp64", b64_picture); |
74 array->EndDictionary(); | 75 array->EndDictionary(); |
75 } | 76 } |
76 | 77 |
77 } // namespace cc | 78 } // namespace cc |
OLD | NEW |