Update V8 to version 4.6.55.
[chromium-blink-merge.git] / cc / playback / drawing_display_item.cc
blob6cebed2ae005fd3767a7af3f4cfb576cd3b0abb2
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
3 // found in the LICENSE file.
5 #include "cc/playback/drawing_display_item.h"
7 #include <string>
9 #include "base/strings/stringprintf.h"
10 #include "base/trace_event/trace_event_argument.h"
11 #include "cc/debug/picture_debug_util.h"
12 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkMatrix.h"
14 #include "third_party/skia/include/core/SkPicture.h"
15 #include "third_party/skia/include/utils/SkPictureUtils.h"
16 #include "ui/gfx/skia_util.h"
18 namespace cc {
20 DrawingDisplayItem::DrawingDisplayItem() {
23 DrawingDisplayItem::~DrawingDisplayItem() {
26 void DrawingDisplayItem::SetNew(skia::RefPtr<SkPicture> picture) {
27 picture_ = picture.Pass();
28 DisplayItem::SetNew(picture_->suitableForGpuRasterization(NULL),
29 picture_->approximateOpCount(),
30 SkPictureUtils::ApproximateBytesUsed(picture_.get()));
33 void DrawingDisplayItem::Raster(SkCanvas* canvas,
34 const gfx::Rect& canvas_target_playback_rect,
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;
46 // SkPicture always does a wrapping save/restore on the canvas, so it is not
47 // necessary here.
48 if (callback)
49 picture_->playback(canvas, callback);
50 else
51 canvas->drawPicture(picture_.get());
54 void DrawingDisplayItem::AsValueInto(
55 base::trace_event::TracedValue* array) const {
56 array->BeginDictionary();
57 array->SetString("name", "DrawingDisplayItem");
58 array->SetString(
59 "cullRect",
60 base::StringPrintf("[%f,%f,%f,%f]", picture_->cullRect().x(),
61 picture_->cullRect().y(), picture_->cullRect().width(),
62 picture_->cullRect().height()));
63 std::string b64_picture;
64 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture);
65 array->SetString("skp64", b64_picture);
66 array->EndDictionary();
69 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const {
70 item->SetNew(picture_);
73 } // namespace cc