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

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

Issue 1094553002: Revert "Speculative revert by sheriff" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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_item_list_unittest.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" 13 #include "cc/debug/traced_picture.h"
14 #include "cc/debug/traced_value.h" 14 #include "cc/debug/traced_value.h"
15 #include "third_party/skia/include/core/SkCanvas.h" 15 #include "third_party/skia/include/core/SkCanvas.h"
16 #include "third_party/skia/include/core/SkDrawPictureCallback.h" 16 #include "third_party/skia/include/core/SkDrawPictureCallback.h"
17 #include "third_party/skia/include/core/SkPictureRecorder.h" 17 #include "third_party/skia/include/core/SkPictureRecorder.h"
18 #include "third_party/skia/include/utils/SkPictureUtils.h" 18 #include "third_party/skia/include/utils/SkPictureUtils.h"
19 #include "ui/gfx/skia_util.h" 19 #include "ui/gfx/skia_util.h"
20 20
21 namespace cc { 21 namespace cc {
22 22
23 DisplayItemList::DisplayItemList() 23 DisplayItemList::DisplayItemList(gfx::Rect layer_rect, bool use_cached_picture)
24 : is_suitable_for_gpu_rasterization_(true), approximate_op_count_(0) { 24 : recorder_(new SkPictureRecorder()),
25 use_cached_picture_(use_cached_picture),
26 retain_individual_display_items_(!use_cached_picture),
27 layer_rect_(layer_rect),
28 is_suitable_for_gpu_rasterization_(true),
29 approximate_op_count_(0) {
30 if (use_cached_picture_) {
31 SkRTreeFactory factory;
32 recorder_.reset(new SkPictureRecorder());
33 canvas_ = skia::SharePtr(recorder_->beginRecording(
34 layer_rect_.width(), layer_rect_.height(), &factory));
35 canvas_->translate(-layer_rect_.x(), -layer_rect_.y());
36 canvas_->clipRect(gfx::RectToSkRect(layer_rect_));
37
38 bool tracing_enabled;
39 TRACE_EVENT_CATEGORY_GROUP_ENABLED(
40 TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") ","
41 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"),
42 &tracing_enabled);
43 if (tracing_enabled)
44 retain_individual_display_items_ = true;
45 }
25 } 46 }
26 47
27 scoped_refptr<DisplayItemList> DisplayItemList::Create() { 48 scoped_refptr<DisplayItemList> DisplayItemList::Create(
28 return make_scoped_refptr(new DisplayItemList()); 49 gfx::Rect layer_rect,
50 bool use_cached_picture) {
51 return make_scoped_refptr(
52 new DisplayItemList(layer_rect, use_cached_picture));
29 } 53 }
30 54
31 DisplayItemList::~DisplayItemList() { 55 DisplayItemList::~DisplayItemList() {
32 } 56 }
33 57
34 void DisplayItemList::Raster(SkCanvas* canvas, 58 void DisplayItemList::Raster(SkCanvas* canvas,
35 SkDrawPictureCallback* callback, 59 SkDrawPictureCallback* callback,
36 float contents_scale) const { 60 float contents_scale) const {
37 if (!picture_) { 61 if (!use_cached_picture_) {
38 canvas->save(); 62 canvas->save();
39 canvas->scale(contents_scale, contents_scale); 63 canvas->scale(contents_scale, contents_scale);
40 for (size_t i = 0; i < items_.size(); ++i) { 64 for (size_t i = 0; i < items_.size(); ++i) {
41 items_[i]->Raster(canvas, callback); 65 items_[i]->Raster(canvas, callback);
42 } 66 }
43 canvas->restore(); 67 canvas->restore();
44 } else { 68 } else {
45 DCHECK(picture_); 69 DCHECK(picture_);
46 70
47 canvas->save(); 71 canvas->save();
48 canvas->scale(contents_scale, contents_scale); 72 canvas->scale(contents_scale, contents_scale);
49 canvas->translate(layer_rect_.x(), layer_rect_.y()); 73 canvas->translate(layer_rect_.x(), layer_rect_.y());
50 if (callback) { 74 if (callback) {
51 // If we have a callback, we need to call |draw()|, |drawPicture()| 75 // If we have a callback, we need to call |draw()|, |drawPicture()|
52 // doesn't take a callback. This is used by |AnalysisCanvas| to early 76 // doesn't take a callback. This is used by |AnalysisCanvas| to early
53 // out. 77 // out.
54 picture_->playback(canvas, callback); 78 picture_->playback(canvas, callback);
55 } else { 79 } else {
56 // Prefer to call |drawPicture()| on the canvas since it could place the 80 // Prefer to call |drawPicture()| on the canvas since it could place the
57 // entire picture on the canvas instead of parsing the skia operations. 81 // entire picture on the canvas instead of parsing the skia operations.
58 canvas->drawPicture(picture_.get()); 82 canvas->drawPicture(picture_.get());
59 } 83 }
60 canvas->restore(); 84 canvas->restore();
61 } 85 }
62 } 86 }
63 87
64 void DisplayItemList::CreateAndCacheSkPicture() { 88 void DisplayItemList::CreateAndCacheSkPicture() {
65 // Convert to an SkPicture for faster rasterization. Code is identical to 89 // Convert to an SkPicture for faster rasterization.
66 // that in Picture::Record. 90 DCHECK(use_cached_picture_);
67 SkRTreeFactory factory; 91 picture_ = skia::AdoptRef(recorder_->endRecordingAsPicture());
68 SkPictureRecorder recorder;
69 skia::RefPtr<SkCanvas> canvas;
70 canvas = skia::SharePtr(recorder.beginRecording(
71 layer_rect_.width(), layer_rect_.height(), &factory));
72 canvas->translate(-layer_rect_.x(), -layer_rect_.y());
73 canvas->clipRect(gfx::RectToSkRect(layer_rect_));
74 for (size_t i = 0; i < items_.size(); ++i)
75 items_[i]->Raster(canvas.get(), NULL);
76 picture_ = skia::AdoptRef(recorder.endRecordingAsPicture());
77 DCHECK(picture_); 92 DCHECK(picture_);
93 recorder_.reset();
94 canvas_.clear();
78 } 95 }
79 96
80 void DisplayItemList::AppendItem(scoped_ptr<DisplayItem> item) { 97 void DisplayItemList::AppendItem(scoped_ptr<DisplayItem> item) {
81 is_suitable_for_gpu_rasterization_ &= item->IsSuitableForGpuRasterization(); 98 is_suitable_for_gpu_rasterization_ &= item->IsSuitableForGpuRasterization();
82 approximate_op_count_ += item->ApproximateOpCount(); 99 approximate_op_count_ += item->ApproximateOpCount();
83 items_.push_back(item.Pass()); 100
101 if (use_cached_picture_) {
102 DCHECK(canvas_);
103 item->Raster(canvas_.get(), NULL);
104 }
105
106 if (retain_individual_display_items_)
107 items_.push_back(item.Pass());
84 } 108 }
85 109
86 bool DisplayItemList::IsSuitableForGpuRasterization() const { 110 bool DisplayItemList::IsSuitableForGpuRasterization() const {
87 // This is more permissive than Picture's implementation, since none of the 111 // This is more permissive than Picture's implementation, since none of the
88 // items might individually trigger a veto even though they collectively have 112 // items might individually trigger a veto even though they collectively have
89 // enough "bad" operations that a corresponding Picture would get vetoed. 113 // enough "bad" operations that a corresponding Picture would get vetoed.
90 return is_suitable_for_gpu_rasterization_; 114 return is_suitable_for_gpu_rasterization_;
91 } 115 }
92 116
93 int DisplayItemList::ApproximateOpCount() const { 117 int DisplayItemList::ApproximateOpCount() const {
(...skipping 25 matching lines...) Expand all
119 } 143 }
120 state->EndArray(); 144 state->EndArray();
121 state->SetValue("params.layer_rect", 145 state->SetValue("params.layer_rect",
122 MathUtil::AsValue(layer_rect_).release()); 146 MathUtil::AsValue(layer_rect_).release());
123 147
124 SkPictureRecorder recorder; 148 SkPictureRecorder recorder;
125 SkCanvas* canvas = 149 SkCanvas* canvas =
126 recorder.beginRecording(layer_rect_.width(), layer_rect_.height()); 150 recorder.beginRecording(layer_rect_.width(), layer_rect_.height());
127 canvas->translate(-layer_rect_.x(), -layer_rect_.y()); 151 canvas->translate(-layer_rect_.x(), -layer_rect_.y());
128 canvas->clipRect(gfx::RectToSkRect(layer_rect_)); 152 canvas->clipRect(gfx::RectToSkRect(layer_rect_));
129 for (size_t i = 0; i < items_.size(); ++i) 153 Raster(canvas, NULL, 1.f);
130 items_[i]->RasterForTracing(canvas);
131 skia::RefPtr<SkPicture> picture = 154 skia::RefPtr<SkPicture> picture =
132 skia::AdoptRef(recorder.endRecordingAsPicture()); 155 skia::AdoptRef(recorder.endRecordingAsPicture());
133 156
134 std::string b64_picture; 157 std::string b64_picture;
135 PictureDebugUtil::SerializeAsBase64(picture.get(), &b64_picture); 158 PictureDebugUtil::SerializeAsBase64(picture.get(), &b64_picture);
136 state->SetString("skp64", b64_picture); 159 state->SetString("skp64", b64_picture);
137 160
138 return state; 161 return state;
139 } 162 }
140 163
141 void DisplayItemList::EmitTraceSnapshot() const { 164 void DisplayItemList::EmitTraceSnapshot() const {
142 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( 165 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
143 TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") "," 166 TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") ","
144 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"), 167 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"),
145 "cc::DisplayItemList", this, AsValue()); 168 "cc::DisplayItemList", this, AsValue());
146 } 169 }
147 170
148 void DisplayItemList::GatherPixelRefs(const gfx::Size& grid_cell_size) { 171 void DisplayItemList::GatherPixelRefs(const gfx::Size& grid_cell_size) {
149 // This should be only called once, and only after CreateAndCacheSkPicture. 172 // This should be only called once, and only after CreateAndCacheSkPicture.
150 DCHECK(picture_); 173 DCHECK(picture_);
151 DCHECK(!pixel_refs_); 174 DCHECK(!pixel_refs_);
152 pixel_refs_ = make_scoped_ptr(new PixelRefMap(grid_cell_size)); 175 pixel_refs_ = make_scoped_ptr(new PixelRefMap(grid_cell_size));
153 if (!picture_->willPlayBackBitmaps()) 176 if (!picture_->willPlayBackBitmaps())
154 return; 177 return;
155 178
156 pixel_refs_->GatherPixelRefsFromPicture(picture_.get()); 179 pixel_refs_->GatherPixelRefsFromPicture(picture_.get());
157 } 180 }
158 } // namespace cc 181 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/display_item_list.h ('k') | cc/resources/display_item_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698