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