Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: cc/resources/display_item_list.cc

Issue 997173003: Revert of Raster into an SkP before rendering a DisplayList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/display_item_list.h ('k') | cc/resources/display_list_recording_source.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "cc/base/math_util.h" 11 #include "cc/base/math_util.h"
12 #include "cc/debug/picture_debug_util.h" 12 #include "cc/debug/picture_debug_util.h"
13 #include "cc/debug/traced_picture.h"
14 #include "cc/debug/traced_value.h"
15 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
16 #include "third_party/skia/include/core/SkDrawPictureCallback.h"
17 #include "third_party/skia/include/core/SkPictureRecorder.h" 14 #include "third_party/skia/include/core/SkPictureRecorder.h"
18 #include "third_party/skia/include/utils/SkPictureUtils.h"
19 #include "ui/gfx/skia_util.h" 15 #include "ui/gfx/skia_util.h"
20 16
21 namespace cc { 17 namespace cc {
22 18
23 DisplayItemList::DisplayItemList() 19 DisplayItemList::DisplayItemList()
24 : is_suitable_for_gpu_rasterization_(true), approximate_op_count_(0) { 20 : is_suitable_for_gpu_rasterization_(true), approximate_op_count_(0) {
25 } 21 }
26 22
27 scoped_refptr<DisplayItemList> DisplayItemList::Create() { 23 scoped_refptr<DisplayItemList> DisplayItemList::Create() {
28 return make_scoped_refptr(new DisplayItemList()); 24 return make_scoped_refptr(new DisplayItemList());
29 } 25 }
30 26
31 DisplayItemList::~DisplayItemList() { 27 DisplayItemList::~DisplayItemList() {
32 } 28 }
33 29
34 void DisplayItemList::Raster(SkCanvas* canvas, 30 void DisplayItemList::Raster(SkCanvas* canvas,
35 SkDrawPictureCallback* callback, 31 SkDrawPictureCallback* callback,
36 float contents_scale) const { 32 float contents_scale) const {
37 if (!picture_) { 33 canvas->save();
38 canvas->save(); 34 canvas->scale(contents_scale, contents_scale);
39 canvas->scale(contents_scale, contents_scale); 35 for (size_t i = 0; i < items_.size(); ++i) {
40 for (size_t i = 0; i < items_.size(); ++i) { 36 items_[i]->Raster(canvas, callback);
41 items_[i]->Raster(canvas, callback);
42 }
43 canvas->restore();
44 } else {
45 DCHECK(picture_);
46
47 canvas->save();
48 canvas->scale(contents_scale, contents_scale);
49 if (callback) {
50 // If we have a callback, we need to call |draw()|, |drawPicture()|
51 // doesn't take a callback. This is used by |AnalysisCanvas| to early
52 // out.
53 picture_->playback(canvas, callback);
54 } else {
55 // Prefer to call |drawPicture()| on the canvas since it could place the
56 // entire picture on the canvas instead of parsing the skia operations.
57 canvas->drawPicture(picture_.get());
58 }
59 canvas->restore();
60 } 37 }
61 } 38 canvas->restore();
62
63 void DisplayItemList::CreateAndCacheSkPicture() {
64 // Convert to an SkPicture for faster rasterization. Code is identical to
65 // that in Picture::Record.
66 SkRTreeFactory factory;
67 SkPictureRecorder recorder;
68 skia::RefPtr<SkCanvas> canvas;
69 canvas = skia::SharePtr(recorder.beginRecording(
70 layer_rect_.width(), layer_rect_.height(), &factory));
71 canvas->translate(-layer_rect_.x(), -layer_rect_.y());
72 canvas->clipRect(gfx::RectToSkRect(layer_rect_));
73 for (size_t i = 0; i < items_.size(); ++i)
74 items_[i]->Raster(canvas.get(), NULL);
75 picture_ = skia::AdoptRef(recorder.endRecording());
76 DCHECK(picture_);
77 } 39 }
78 40
79 void DisplayItemList::AppendItem(scoped_ptr<DisplayItem> item) { 41 void DisplayItemList::AppendItem(scoped_ptr<DisplayItem> item) {
80 is_suitable_for_gpu_rasterization_ &= item->IsSuitableForGpuRasterization(); 42 is_suitable_for_gpu_rasterization_ &= item->IsSuitableForGpuRasterization();
81 approximate_op_count_ += item->ApproximateOpCount(); 43 approximate_op_count_ += item->ApproximateOpCount();
82 items_.push_back(item.Pass()); 44 items_.push_back(item.Pass());
83 } 45 }
84 46
85 bool DisplayItemList::IsSuitableForGpuRasterization() const { 47 bool DisplayItemList::IsSuitableForGpuRasterization() const {
86 // This is more permissive than Picture's implementation, since none of the 48 // This is more permissive than Picture's implementation, since none of the
87 // items might individually trigger a veto even though they collectively have 49 // items might individually trigger a veto even though they collectively have
88 // enough "bad" operations that a corresponding Picture would get vetoed. 50 // enough "bad" operations that a corresponding Picture would get vetoed.
89 return is_suitable_for_gpu_rasterization_; 51 return is_suitable_for_gpu_rasterization_;
90 } 52 }
91 53
92 int DisplayItemList::ApproximateOpCount() const { 54 int DisplayItemList::ApproximateOpCount() const {
93 return approximate_op_count_; 55 return approximate_op_count_;
94 } 56 }
95 57
96 size_t DisplayItemList::PictureMemoryUsage() const { 58 size_t DisplayItemList::PictureMemoryUsage() const {
97 size_t total_size = 0; 59 size_t total_size = 0;
98 60
99 for (const auto& item : items_) { 61 for (const auto& item : items_) {
100 total_size += item->PictureMemoryUsage(); 62 total_size += item->PictureMemoryUsage();
101 } 63 }
102 64
103 if (picture_)
104 total_size += SkPictureUtils::ApproximateBytesUsed(picture_.get());
105
106 return total_size; 65 return total_size;
107 } 66 }
108 67
109 scoped_refptr<base::trace_event::ConvertableToTraceFormat> 68 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
110 DisplayItemList::AsValue() const { 69 DisplayItemList::AsValue() const {
111 scoped_refptr<base::trace_event::TracedValue> state = 70 scoped_refptr<base::trace_event::TracedValue> state =
112 new base::trace_event::TracedValue(); 71 new base::trace_event::TracedValue();
113 72
114 state->SetInteger("length", items_.size()); 73 state->SetInteger("length", items_.size());
115 state->BeginArray("params.items"); 74 state->BeginArray("params.items");
(...skipping 21 matching lines...) Expand all
137 } 96 }
138 97
139 void DisplayItemList::EmitTraceSnapshot() const { 98 void DisplayItemList::EmitTraceSnapshot() const {
140 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( 99 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
141 TRACE_DISABLED_BY_DEFAULT("cc.debug") "," TRACE_DISABLED_BY_DEFAULT( 100 TRACE_DISABLED_BY_DEFAULT("cc.debug") "," TRACE_DISABLED_BY_DEFAULT(
142 "devtools.timeline.picture"), 101 "devtools.timeline.picture"),
143 "cc::DisplayItemList", this, AsValue()); 102 "cc::DisplayItemList", this, AsValue());
144 } 103 }
145 104
146 } // namespace cc 105 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/display_item_list.h ('k') | cc/resources/display_list_recording_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698