| 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/display_item_list.h" | 5 #include "cc/resources/display_item_list.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "base/trace_event/trace_event_argument.h" | 10 #include "base/trace_event/trace_event_argument.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // that in Picture::Record. | 65 // that in Picture::Record. |
| 66 SkRTreeFactory factory; | 66 SkRTreeFactory factory; |
| 67 SkPictureRecorder recorder; | 67 SkPictureRecorder recorder; |
| 68 skia::RefPtr<SkCanvas> canvas; | 68 skia::RefPtr<SkCanvas> canvas; |
| 69 canvas = skia::SharePtr(recorder.beginRecording( | 69 canvas = skia::SharePtr(recorder.beginRecording( |
| 70 layer_rect_.width(), layer_rect_.height(), &factory)); | 70 layer_rect_.width(), layer_rect_.height(), &factory)); |
| 71 canvas->translate(-layer_rect_.x(), -layer_rect_.y()); | 71 canvas->translate(-layer_rect_.x(), -layer_rect_.y()); |
| 72 canvas->clipRect(gfx::RectToSkRect(layer_rect_)); | 72 canvas->clipRect(gfx::RectToSkRect(layer_rect_)); |
| 73 for (size_t i = 0; i < items_.size(); ++i) | 73 for (size_t i = 0; i < items_.size(); ++i) |
| 74 items_[i]->Raster(canvas.get(), NULL); | 74 items_[i]->Raster(canvas.get(), NULL); |
| 75 picture_ = skia::AdoptRef(recorder.endRecording()); | 75 picture_ = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 76 DCHECK(picture_); | 76 DCHECK(picture_); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void DisplayItemList::AppendItem(scoped_ptr<DisplayItem> item) { | 79 void DisplayItemList::AppendItem(scoped_ptr<DisplayItem> item) { |
| 80 is_suitable_for_gpu_rasterization_ &= item->IsSuitableForGpuRasterization(); | 80 is_suitable_for_gpu_rasterization_ &= item->IsSuitableForGpuRasterization(); |
| 81 approximate_op_count_ += item->ApproximateOpCount(); | 81 approximate_op_count_ += item->ApproximateOpCount(); |
| 82 items_.push_back(item.Pass()); | 82 items_.push_back(item.Pass()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool DisplayItemList::IsSuitableForGpuRasterization() const { | 85 bool DisplayItemList::IsSuitableForGpuRasterization() const { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 state->SetValue("params.layer_rect", | 120 state->SetValue("params.layer_rect", |
| 121 MathUtil::AsValue(layer_rect_).release()); | 121 MathUtil::AsValue(layer_rect_).release()); |
| 122 | 122 |
| 123 SkPictureRecorder recorder; | 123 SkPictureRecorder recorder; |
| 124 SkCanvas* canvas = | 124 SkCanvas* canvas = |
| 125 recorder.beginRecording(layer_rect_.width(), layer_rect_.height()); | 125 recorder.beginRecording(layer_rect_.width(), layer_rect_.height()); |
| 126 canvas->translate(-layer_rect_.x(), -layer_rect_.y()); | 126 canvas->translate(-layer_rect_.x(), -layer_rect_.y()); |
| 127 canvas->clipRect(gfx::RectToSkRect(layer_rect_)); | 127 canvas->clipRect(gfx::RectToSkRect(layer_rect_)); |
| 128 for (size_t i = 0; i < items_.size(); ++i) | 128 for (size_t i = 0; i < items_.size(); ++i) |
| 129 items_[i]->RasterForTracing(canvas); | 129 items_[i]->RasterForTracing(canvas); |
| 130 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 130 skia::RefPtr<SkPicture> picture = |
| 131 skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 131 | 132 |
| 132 std::string b64_picture; | 133 std::string b64_picture; |
| 133 PictureDebugUtil::SerializeAsBase64(picture.get(), &b64_picture); | 134 PictureDebugUtil::SerializeAsBase64(picture.get(), &b64_picture); |
| 134 state->SetString("skp64", b64_picture); | 135 state->SetString("skp64", b64_picture); |
| 135 | 136 |
| 136 return state; | 137 return state; |
| 137 } | 138 } |
| 138 | 139 |
| 139 void DisplayItemList::EmitTraceSnapshot() const { | 140 void DisplayItemList::EmitTraceSnapshot() const { |
| 140 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | 141 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
| 141 TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") "," | 142 TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") "," |
| 142 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"), | 143 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"), |
| 143 "cc::DisplayItemList", this, AsValue()); | 144 "cc::DisplayItemList", this, AsValue()); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void DisplayItemList::GatherPixelRefs(const gfx::Size& grid_cell_size) { | 147 void DisplayItemList::GatherPixelRefs(const gfx::Size& grid_cell_size) { |
| 147 // This should be only called once, and only after CreateAndCacheSkPicture. | 148 // This should be only called once, and only after CreateAndCacheSkPicture. |
| 148 DCHECK(picture_); | 149 DCHECK(picture_); |
| 149 DCHECK(!pixel_refs_); | 150 DCHECK(!pixel_refs_); |
| 150 pixel_refs_ = make_scoped_ptr(new PixelRefMap(grid_cell_size)); | 151 pixel_refs_ = make_scoped_ptr(new PixelRefMap(grid_cell_size)); |
| 151 if (!picture_->willPlayBackBitmaps()) | 152 if (!picture_->willPlayBackBitmaps()) |
| 152 return; | 153 return; |
| 153 | 154 |
| 154 pixel_refs_->GatherPixelRefsFromPicture(picture_.get()); | 155 pixel_refs_->GatherPixelRefsFromPicture(picture_.get()); |
| 155 } | 156 } |
| 156 } // namespace cc | 157 } // namespace cc |
| OLD | NEW |