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 |
11 #include "base/base64.h" | 11 #include "base/base64.h" |
12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
15 #include "cc/base/util.h" | 15 #include "cc/base/util.h" |
16 #include "cc/debug/rendering_stats.h" | 16 #include "cc/debug/rendering_stats.h" |
17 #include "cc/debug/traced_picture.h" | 17 #include "cc/debug/traced_picture.h" |
18 #include "cc/debug/traced_value.h" | 18 #include "cc/debug/traced_value.h" |
19 #include "cc/layers/content_layer_client.h" | 19 #include "cc/layers/content_layer_client.h" |
20 #include "skia/ext/analysis_canvas.h" | 20 #include "skia/ext/lazy_pixel_ref_utils.h" |
21 #include "third_party/skia/include/core/SkCanvas.h" | 21 #include "third_party/skia/include/core/SkCanvas.h" |
22 #include "third_party/skia/include/core/SkData.h" | 22 #include "third_party/skia/include/core/SkData.h" |
23 #include "third_party/skia/include/core/SkDrawFilter.h" | 23 #include "third_party/skia/include/core/SkDrawFilter.h" |
24 #include "third_party/skia/include/core/SkPaint.h" | 24 #include "third_party/skia/include/core/SkPaint.h" |
25 #include "third_party/skia/include/core/SkStream.h" | 25 #include "third_party/skia/include/core/SkStream.h" |
26 #include "third_party/skia/include/utils/SkPictureUtils.h" | 26 #include "third_party/skia/include/utils/SkPictureUtils.h" |
27 #include "ui/gfx/codec/jpeg_codec.h" | 27 #include "ui/gfx/codec/jpeg_codec.h" |
28 #include "ui/gfx/codec/png_codec.h" | 28 #include "ui/gfx/codec/png_codec.h" |
29 #include "ui/gfx/rect_conversions.h" | 29 #include "ui/gfx/rect_conversions.h" |
30 #include "ui/gfx/skia_util.h" | 30 #include "ui/gfx/skia_util.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // SkDrawFilter interface. | 85 // SkDrawFilter interface. |
86 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE { | 86 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE { |
87 if (type != SkDrawFilter::kText_Type) | 87 if (type != SkDrawFilter::kText_Type) |
88 return true; | 88 return true; |
89 | 89 |
90 paint->setLCDRenderText(false); | 90 paint->setLCDRenderText(false); |
91 return true; | 91 return true; |
92 } | 92 } |
93 }; | 93 }; |
94 | 94 |
95 // URI label for a lazily decoded SkPixelRef. | |
96 const char kLabelLazyDecoded[] = "lazy"; | |
97 | |
98 void GatherPixelRefsForRect( | |
99 SkPicture* picture, | |
100 gfx::Rect rect, | |
101 Picture::PixelRefs* pixel_refs) { | |
102 DCHECK(picture); | |
103 SkData* pixel_ref_data = SkPictureUtils::GatherPixelRefs( | |
104 picture, | |
105 gfx::RectToSkRect(rect)); | |
106 if (!pixel_ref_data) | |
107 return; | |
108 | |
109 void* data = const_cast<void*>(pixel_ref_data->data()); | |
110 if (!data) { | |
111 pixel_ref_data->unref(); | |
112 return; | |
113 } | |
114 | |
115 SkPixelRef** refs = reinterpret_cast<SkPixelRef**>(data); | |
116 for (size_t i = 0; i < pixel_ref_data->size() / sizeof(*refs); ++i) { | |
117 if (*refs && (*refs)->getURI() && | |
118 !strncmp((*refs)->getURI(), kLabelLazyDecoded, 4)) { | |
119 pixel_refs->push_back(static_cast<skia::LazyPixelRef*>(*refs)); | |
120 } | |
121 refs++; | |
122 } | |
123 pixel_ref_data->unref(); | |
124 } | |
125 | |
126 } // namespace | 95 } // namespace |
127 | 96 |
128 scoped_refptr<Picture> Picture::Create(gfx::Rect layer_rect) { | 97 scoped_refptr<Picture> Picture::Create(gfx::Rect layer_rect) { |
129 return make_scoped_refptr(new Picture(layer_rect)); | 98 return make_scoped_refptr(new Picture(layer_rect)); |
130 } | 99 } |
131 | 100 |
132 scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* value) { | 101 scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* value) { |
133 bool success; | 102 bool success; |
134 scoped_refptr<Picture> picture = | 103 scoped_refptr<Picture> picture = |
135 make_scoped_refptr(new Picture(value, &success)); | 104 make_scoped_refptr(new Picture(value, &success)); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 264 |
296 int min_x = std::numeric_limits<int>::max(); | 265 int min_x = std::numeric_limits<int>::max(); |
297 int min_y = std::numeric_limits<int>::max(); | 266 int min_y = std::numeric_limits<int>::max(); |
298 int max_x = 0; | 267 int max_x = 0; |
299 int max_y = 0; | 268 int max_y = 0; |
300 | 269 |
301 base::TimeTicks begin_image_gathering_time; | 270 base::TimeTicks begin_image_gathering_time; |
302 if (stats) | 271 if (stats) |
303 begin_image_gathering_time = base::TimeTicks::Now(); | 272 begin_image_gathering_time = base::TimeTicks::Now(); |
304 | 273 |
305 gfx::Size layer_size(layer_rect_.size()); | 274 skia::LazyPixelRefList pixel_refs; |
| 275 skia::LazyPixelRefUtils::GatherPixelRefs(picture_.get(), &pixel_refs); |
| 276 for (skia::LazyPixelRefList::const_iterator it = pixel_refs.begin(); |
| 277 it != pixel_refs.end(); |
| 278 ++it) { |
| 279 gfx::Point min( |
| 280 RoundDown(static_cast<int>(it->pixel_ref_rect.x()), |
| 281 cell_size_.width()), |
| 282 RoundDown(static_cast<int>(it->pixel_ref_rect.y()), |
| 283 cell_size_.height())); |
| 284 gfx::Point max( |
| 285 RoundDown(static_cast<int>(std::ceil(it->pixel_ref_rect.right())), |
| 286 cell_size_.width()), |
| 287 RoundDown(static_cast<int>(std::ceil(it->pixel_ref_rect.bottom())), |
| 288 cell_size_.height())); |
306 | 289 |
307 // Capture pixel refs for this picture in a grid | 290 for (int y = min.y(); y <= max.y(); y += cell_size_.height()) { |
308 // with cell_size_ sized cells. | 291 for (int x = min.x(); x <= max.x(); x += cell_size_.width()) { |
309 pixel_refs_.clear(); | |
310 for (int y = 0; y < layer_rect_.height(); y += cell_size_.height()) { | |
311 for (int x = 0; x < layer_rect_.width(); x += cell_size_.width()) { | |
312 gfx::Rect rect(gfx::Point(x, y), cell_size_); | |
313 rect.Intersect(gfx::Rect(gfx::Point(), layer_rect_.size())); | |
314 | |
315 PixelRefs pixel_refs; | |
316 GatherPixelRefsForRect(picture_.get(), rect, &pixel_refs); | |
317 | |
318 // Only capture non-empty cells. | |
319 if (!pixel_refs.empty()) { | |
320 PixelRefMapKey key(x, y); | 292 PixelRefMapKey key(x, y); |
321 pixel_refs_[key].swap(pixel_refs); | 293 pixel_refs_[key].push_back(it->lazy_pixel_ref); |
322 min_x = std::min(min_x, x); | |
323 min_y = std::min(min_y, y); | |
324 max_x = std::max(max_x, x); | |
325 max_y = std::max(max_y, y); | |
326 } | 294 } |
327 } | 295 } |
| 296 |
| 297 min_x = std::min(min_x, min.x()); |
| 298 min_y = std::min(min_y, min.y()); |
| 299 max_x = std::max(max_x, max.x()); |
| 300 max_y = std::max(max_y, max.y()); |
328 } | 301 } |
329 | 302 |
330 if (stats) { | 303 if (stats) { |
331 stats->total_image_gathering_time += | 304 stats->total_image_gathering_time += |
332 base::TimeTicks::Now() - begin_image_gathering_time; | 305 base::TimeTicks::Now() - begin_image_gathering_time; |
333 stats->total_image_gathering_count++; | 306 stats->total_image_gathering_count++; |
334 } | 307 } |
335 | 308 |
336 min_pixel_cell_ = gfx::Point(min_x, min_y); | 309 min_pixel_cell_ = gfx::Point(min_x, min_y); |
337 max_pixel_cell_ = gfx::Point(max_x, max_y); | 310 max_pixel_cell_ = gfx::Point(max_x, max_y); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 raster_data->Set("picture_id", TracedValue::CreateIDRef(this).release()); | 465 raster_data->Set("picture_id", TracedValue::CreateIDRef(this).release()); |
493 raster_data->SetDouble("scale", scale); | 466 raster_data->SetDouble("scale", scale); |
494 raster_data->SetDouble("rect_x", rect.x()); | 467 raster_data->SetDouble("rect_x", rect.x()); |
495 raster_data->SetDouble("rect_y", rect.y()); | 468 raster_data->SetDouble("rect_y", rect.y()); |
496 raster_data->SetDouble("rect_width", rect.width()); | 469 raster_data->SetDouble("rect_width", rect.width()); |
497 raster_data->SetDouble("rect_height", rect.height()); | 470 raster_data->SetDouble("rect_height", rect.height()); |
498 return TracedValue::FromValue(raster_data.release()); | 471 return TracedValue::FromValue(raster_data.release()); |
499 } | 472 } |
500 | 473 |
501 } // namespace cc | 474 } // namespace cc |
OLD | NEW |