Chromium Code Reviews| 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/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/SkDrawPictureCallback.h" | 13 #include "third_party/skia/include/core/SkDrawPictureCallback.h" |
| 14 #include "third_party/skia/include/core/SkMatrix.h" | 14 #include "third_party/skia/include/core/SkMatrix.h" |
| 15 #include "third_party/skia/include/core/SkPicture.h" | 15 #include "third_party/skia/include/core/SkPicture.h" |
| 16 #include "third_party/skia/include/utils/SkPictureUtils.h" | 16 #include "third_party/skia/include/utils/SkPictureUtils.h" |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 | 19 |
| 20 DrawingDisplayItem::DrawingDisplayItem(skia::RefPtr<SkPicture> picture, | 20 DrawingDisplayItem::DrawingDisplayItem(skia::RefPtr<SkPicture> picture) |
| 21 gfx::PointF location) | 21 : picture_(picture) { |
| 22 : picture_(picture), location_(location) { | |
| 23 } | 22 } |
| 24 | 23 |
| 25 DrawingDisplayItem::~DrawingDisplayItem() { | 24 DrawingDisplayItem::~DrawingDisplayItem() { |
| 26 } | 25 } |
| 27 | 26 |
| 28 void DrawingDisplayItem::Raster(SkCanvas* canvas, | 27 void DrawingDisplayItem::Raster(SkCanvas* canvas, |
| 29 SkDrawPictureCallback* callback) const { | 28 SkDrawPictureCallback* callback) const { |
| 30 canvas->save(); | 29 canvas->save(); |
| 31 canvas->translate(location_.x(), location_.y()); | 30 canvas->translate(picture_->cullRect().x(), picture_->cullRect().y()); |
|
ajuma
2015/02/17 22:43:30
Since location_ is currently being set to (0, 0),
Stephen Chennney
2015/02/19 15:36:52
Done. The unit test needed updating to match.
| |
| 32 if (callback) | 31 if (callback) |
| 33 picture_->playback(canvas, callback); | 32 picture_->playback(canvas, callback); |
| 34 else | 33 else |
| 35 canvas->drawPicture(picture_.get()); | 34 canvas->drawPicture(picture_.get()); |
| 36 canvas->restore(); | 35 canvas->restore(); |
| 37 } | 36 } |
| 38 | 37 |
| 39 void DrawingDisplayItem::RasterForTracing(SkCanvas* canvas) const { | 38 void DrawingDisplayItem::RasterForTracing(SkCanvas* canvas) const { |
| 40 canvas->save(); | 39 canvas->save(); |
| 41 canvas->translate(location_.x(), location_.y()); | 40 canvas->translate(picture_->cullRect().x(), picture_->cullRect().y()); |
| 42 // The picture debugger in about:tracing doesn't drill down into |drawPicture| | 41 // The picture debugger in about:tracing doesn't drill down into |drawPicture| |
| 43 // operations. Calling |playback()| rather than |drawPicture()| causes the | 42 // operations. Calling |playback()| rather than |drawPicture()| causes the |
| 44 // skia operations in |picture_| to appear individually in the picture | 43 // skia operations in |picture_| to appear individually in the picture |
| 45 // produced for tracing rather than being hidden inside a drawPicture | 44 // produced for tracing rather than being hidden inside a drawPicture |
| 46 // operation. | 45 // operation. |
| 47 picture_->playback(canvas); | 46 picture_->playback(canvas); |
| 48 canvas->restore(); | 47 canvas->restore(); |
| 49 } | 48 } |
| 50 | 49 |
| 51 bool DrawingDisplayItem::IsSuitableForGpuRasterization() const { | 50 bool DrawingDisplayItem::IsSuitableForGpuRasterization() const { |
| 52 return picture_->suitableForGpuRasterization(NULL); | 51 return picture_->suitableForGpuRasterization(NULL); |
| 53 } | 52 } |
| 54 | 53 |
| 55 int DrawingDisplayItem::ApproximateOpCount() const { | 54 int DrawingDisplayItem::ApproximateOpCount() const { |
| 56 return picture_->approximateOpCount() + sizeof(gfx::PointF); | 55 return picture_->approximateOpCount() + sizeof(gfx::PointF); |
| 57 } | 56 } |
| 58 | 57 |
| 59 size_t DrawingDisplayItem::PictureMemoryUsage() const { | 58 size_t DrawingDisplayItem::PictureMemoryUsage() const { |
| 60 DCHECK(picture_); | 59 DCHECK(picture_); |
| 61 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); | 60 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); |
| 62 } | 61 } |
| 63 | 62 |
| 64 void DrawingDisplayItem::AsValueInto( | 63 void DrawingDisplayItem::AsValueInto( |
| 65 base::trace_event::TracedValue* array) const { | 64 base::trace_event::TracedValue* array) const { |
| 66 array->BeginDictionary(); | 65 array->BeginDictionary(); |
| 67 array->SetString("name", "DrawingDisplayItem"); | 66 array->SetString("name", "DrawingDisplayItem"); |
| 68 array->SetString("location", | 67 array->SetString( |
| 69 base::StringPrintf("[%f,%f]", picture_->cullRect().x(), | 68 "cullRect", |
| 70 picture_->cullRect().y())); | 69 base::StringPrintf("[%f,%f,%f,%f]", picture_->cullRect().x(), |
| 70 picture_->cullRect().y(), picture_->cullRect().width(), | |
| 71 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 |