OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/picture.h" | 5 #include "cc/resources/picture.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 const gfx::Rect& layer_rect, | 85 const gfx::Rect& layer_rect, |
86 ContentLayerClient* client, | 86 ContentLayerClient* client, |
87 const SkTileGridPicture::TileGridInfo& tile_grid_info, | 87 const SkTileGridPicture::TileGridInfo& tile_grid_info, |
88 bool gather_pixel_refs, | 88 bool gather_pixel_refs, |
89 int num_raster_threads) { | 89 int num_raster_threads) { |
90 scoped_refptr<Picture> picture = make_scoped_refptr(new Picture(layer_rect)); | 90 scoped_refptr<Picture> picture = make_scoped_refptr(new Picture(layer_rect)); |
91 | 91 |
92 picture->Record(client, tile_grid_info); | 92 picture->Record(client, tile_grid_info); |
93 if (gather_pixel_refs) | 93 if (gather_pixel_refs) |
94 picture->GatherPixelRefs(tile_grid_info); | 94 picture->GatherPixelRefs(tile_grid_info); |
95 if (num_raster_threads > 0) | 95 picture->CloneForDrawing(num_raster_threads); |
96 picture->CloneForDrawing(num_raster_threads); | |
97 | |
98 // This picture may be rasterized on a different thread. | |
99 picture->raster_thread_checker_.DetachFromThread(); | |
100 | 96 |
101 return picture; | 97 return picture; |
102 } | 98 } |
103 | 99 |
104 Picture::Picture(const gfx::Rect& layer_rect) | 100 Picture::Picture(const gfx::Rect& layer_rect) |
105 : layer_rect_(layer_rect), | 101 : layer_rect_(layer_rect), |
106 cell_size_(layer_rect.size()) { | 102 cell_size_(layer_rect.size()) { |
107 // Instead of recording a trace event for object creation here, we wait for | 103 // Instead of recording a trace event for object creation here, we wait for |
108 // the picture to be recorded in Picture::Record. | 104 // the picture to be recorded in Picture::Record. |
109 } | 105 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 picture_(picture), | 181 picture_(picture), |
186 pixel_refs_(pixel_refs), | 182 pixel_refs_(pixel_refs), |
187 cell_size_(layer_rect.size()) { | 183 cell_size_(layer_rect.size()) { |
188 } | 184 } |
189 | 185 |
190 Picture::~Picture() { | 186 Picture::~Picture() { |
191 TRACE_EVENT_OBJECT_DELETED_WITH_ID( | 187 TRACE_EVENT_OBJECT_DELETED_WITH_ID( |
192 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::Picture", this); | 188 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::Picture", this); |
193 } | 189 } |
194 | 190 |
195 scoped_refptr<Picture> Picture::GetCloneForDrawingOnThread( | 191 Picture* Picture::GetCloneForDrawingOnThread(unsigned thread_index) { |
196 unsigned thread_index) const { | |
197 // SkPicture is not thread-safe to rasterize with, this returns a clone | 192 // SkPicture is not thread-safe to rasterize with, this returns a clone |
198 // to rasterize with on a specific thread. | 193 // to rasterize with on a specific thread. |
199 CHECK_GT(clones_.size(), thread_index); | 194 CHECK_GE(clones_.size(), thread_index); |
200 return clones_[thread_index]; | 195 return thread_index == clones_.size() ? this : clones_[thread_index].get(); |
201 } | 196 } |
202 | 197 |
203 void Picture::CloneForDrawing(int num_threads) { | 198 void Picture::CloneForDrawing(int num_threads) { |
204 TRACE_EVENT1("cc", "Picture::CloneForDrawing", "num_threads", num_threads); | 199 TRACE_EVENT1("cc", "Picture::CloneForDrawing", "num_threads", num_threads); |
205 | 200 |
206 DCHECK(picture_); | 201 DCHECK(picture_); |
207 DCHECK(clones_.empty()); | 202 DCHECK(clones_.empty()); |
208 | 203 |
209 scoped_ptr<SkPicture[]> clones(new SkPicture[num_threads]); | 204 // We can re-use this picture for one raster worker thread. |
210 picture_->clone(&clones[0], num_threads); | 205 raster_thread_checker_.DetachFromThread(); |
211 | 206 |
212 for (int i = 0; i < num_threads; i++) { | 207 if (num_threads > 1) { |
213 scoped_refptr<Picture> clone = make_scoped_refptr( | 208 scoped_ptr<SkPicture[]> clones(new SkPicture[num_threads - 1]); |
214 new Picture(skia::AdoptRef(new SkPicture(clones[i])), | 209 picture_->clone(&clones[0], num_threads - 1); |
215 layer_rect_, | |
216 opaque_rect_, | |
217 pixel_refs_)); | |
218 clones_.push_back(clone); | |
219 | 210 |
220 clone->EmitTraceSnapshotAlias(this); | 211 for (int i = 0; i < num_threads - 1; i++) { |
221 clone->raster_thread_checker_.DetachFromThread(); | 212 scoped_refptr<Picture> clone = make_scoped_refptr( |
213 new Picture(skia::AdoptRef(new SkPicture(clones[i])), | |
214 layer_rect_, | |
215 opaque_rect_, | |
216 pixel_refs_)); | |
217 clones_.push_back(clone); | |
218 | |
219 clone->EmitTraceSnapshotAlias(this); | |
enne (OOO)
2014/02/11 22:30:45
Do you need to emit the trace snapshot alias for t
reveman
2014/02/11 23:40:42
Not needed as discussed.
| |
220 clone->raster_thread_checker_.DetachFromThread(); | |
221 } | |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 void Picture::Record(ContentLayerClient* painter, | 225 void Picture::Record(ContentLayerClient* painter, |
226 const SkTileGridPicture::TileGridInfo& tile_grid_info) { | 226 const SkTileGridPicture::TileGridInfo& tile_grid_info) { |
227 TRACE_EVENT1("cc", "Picture::Record", | 227 TRACE_EVENT1("cc", "Picture::Record", |
228 "data", AsTraceableRecordData()); | 228 "data", AsTraceableRecordData()); |
229 | 229 |
230 DCHECK(!picture_); | 230 DCHECK(!picture_); |
231 DCHECK(!tile_grid_info.fTileInterval.isEmpty()); | 231 DCHECK(!tile_grid_info.fTileInterval.isEmpty()); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 scoped_refptr<base::debug::ConvertableToTraceFormat> | 504 scoped_refptr<base::debug::ConvertableToTraceFormat> |
505 Picture::AsTraceableRecordData() const { | 505 Picture::AsTraceableRecordData() const { |
506 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); | 506 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); |
507 record_data->Set("picture_id", TracedValue::CreateIDRef(this).release()); | 507 record_data->Set("picture_id", TracedValue::CreateIDRef(this).release()); |
508 record_data->SetInteger("width", layer_rect_.width()); | 508 record_data->SetInteger("width", layer_rect_.width()); |
509 record_data->SetInteger("height", layer_rect_.height()); | 509 record_data->SetInteger("height", layer_rect_.height()); |
510 return TracedValue::FromValue(record_data.release()); | 510 return TracedValue::FromValue(record_data.release()); |
511 } | 511 } |
512 | 512 |
513 } // namespace cc | 513 } // namespace cc |
OLD | NEW |