| 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/SkDrawPictureCallback.h" | |
| 14 #include "third_party/skia/include/core/SkMatrix.h" | 13 #include "third_party/skia/include/core/SkMatrix.h" |
| 15 #include "third_party/skia/include/core/SkPicture.h" | 14 #include "third_party/skia/include/core/SkPicture.h" |
| 16 #include "third_party/skia/include/utils/SkPictureUtils.h" | 15 #include "third_party/skia/include/utils/SkPictureUtils.h" |
| 17 | 16 |
| 18 namespace cc { | 17 namespace cc { |
| 19 | 18 |
| 20 DrawingDisplayItem::DrawingDisplayItem() { | 19 DrawingDisplayItem::DrawingDisplayItem() { |
| 21 } | 20 } |
| 22 | 21 |
| 23 DrawingDisplayItem::~DrawingDisplayItem() { | 22 DrawingDisplayItem::~DrawingDisplayItem() { |
| 24 } | 23 } |
| 25 | 24 |
| 26 void DrawingDisplayItem::SetNew(skia::RefPtr<SkPicture> picture) { | 25 void DrawingDisplayItem::SetNew(skia::RefPtr<SkPicture> picture) { |
| 27 picture_ = picture.Pass(); | 26 picture_ = picture.Pass(); |
| 28 DisplayItem::SetNew(picture_->suitableForGpuRasterization(NULL), | 27 DisplayItem::SetNew(picture_->suitableForGpuRasterization(NULL), |
| 29 picture_->approximateOpCount(), | 28 picture_->approximateOpCount(), |
| 30 SkPictureUtils::ApproximateBytesUsed(picture_.get())); | 29 SkPictureUtils::ApproximateBytesUsed(picture_.get())); |
| 31 } | 30 } |
| 32 | 31 |
| 33 void DrawingDisplayItem::Raster(SkCanvas* canvas, | 32 void DrawingDisplayItem::Raster(SkCanvas* canvas, |
| 34 SkDrawPictureCallback* callback) const { | 33 SkPicture::AbortCallback* callback) const { |
| 35 // SkPicture always does a wrapping save/restore on the canvas, so it is not | 34 // SkPicture always does a wrapping save/restore on the canvas, so it is not |
| 36 // necessary here. | 35 // necessary here. |
| 37 if (callback) | 36 if (callback) |
| 38 picture_->playback(canvas, callback); | 37 picture_->playback(canvas, callback); |
| 39 else | 38 else |
| 40 canvas->drawPicture(picture_.get()); | 39 canvas->drawPicture(picture_.get()); |
| 41 } | 40 } |
| 42 | 41 |
| 43 void DrawingDisplayItem::AsValueInto( | 42 void DrawingDisplayItem::AsValueInto( |
| 44 base::trace_event::TracedValue* array) const { | 43 base::trace_event::TracedValue* array) const { |
| 45 array->BeginDictionary(); | 44 array->BeginDictionary(); |
| 46 array->SetString("name", "DrawingDisplayItem"); | 45 array->SetString("name", "DrawingDisplayItem"); |
| 47 array->SetString( | 46 array->SetString( |
| 48 "cullRect", | 47 "cullRect", |
| 49 base::StringPrintf("[%f,%f,%f,%f]", picture_->cullRect().x(), | 48 base::StringPrintf("[%f,%f,%f,%f]", picture_->cullRect().x(), |
| 50 picture_->cullRect().y(), picture_->cullRect().width(), | 49 picture_->cullRect().y(), picture_->cullRect().width(), |
| 51 picture_->cullRect().height())); | 50 picture_->cullRect().height())); |
| 52 std::string b64_picture; | 51 std::string b64_picture; |
| 53 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); | 52 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); |
| 54 array->SetString("skp64", b64_picture); | 53 array->SetString("skp64", b64_picture); |
| 55 array->EndDictionary(); | 54 array->EndDictionary(); |
| 56 } | 55 } |
| 57 | 56 |
| 58 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const { | 57 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const { |
| 59 item->SetNew(picture_); | 58 item->SetNew(picture_); |
| 60 } | 59 } |
| 61 | 60 |
| 62 } // namespace cc | 61 } // namespace cc |
| OLD | NEW |