Chromium Code Reviews| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "cc/base/region.h" | 9 #include "cc/base/region.h" |
| 10 #include "cc/debug/debug_colors.h" | 10 #include "cc/debug/debug_colors.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 | 67 |
| 68 PicturePileImpl::~PicturePileImpl() { | 68 PicturePileImpl::~PicturePileImpl() { |
| 69 } | 69 } |
| 70 | 70 |
| 71 PicturePileImpl* PicturePileImpl::GetCloneForDrawingOnThread( | 71 PicturePileImpl* PicturePileImpl::GetCloneForDrawingOnThread( |
| 72 unsigned thread_index) const { | 72 unsigned thread_index) const { |
| 73 CHECK_GT(clones_for_drawing_.clones_.size(), thread_index); | 73 CHECK_GT(clones_for_drawing_.clones_.size(), thread_index); |
| 74 return clones_for_drawing_.clones_[thread_index]; | 74 return clones_for_drawing_.clones_[thread_index]; |
| 75 } | 75 } |
| 76 | 76 |
| 77 void PicturePileImpl::Raster( | 77 void PicturePileImpl::RasterDirect( |
| 78 SkCanvas* canvas, | 78 SkCanvas* canvas, |
| 79 gfx::Rect canvas_rect, | 79 gfx::Rect canvas_rect, |
| 80 float contents_scale, | 80 float contents_scale, |
| 81 RasterStats* raster_stats) { | 81 RasterStats* raster_stats) { |
| 82 | |
| 83 DCHECK(contents_scale >= min_contents_scale_); | 82 DCHECK(contents_scale >= min_contents_scale_); |
| 84 | 83 |
| 85 canvas->save(); | |
| 86 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); | 84 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); |
| 87 | 85 |
| 88 gfx::SizeF total_content_size = gfx::ScaleSize(tiling_.total_size(), | 86 gfx::SizeF total_content_size = gfx::ScaleSize(tiling_.total_size(), |
| 89 contents_scale); | 87 contents_scale); |
| 90 gfx::Rect total_content_rect(gfx::ToCeiledSize(total_content_size)); | 88 gfx::Rect total_content_rect(gfx::ToCeiledSize(total_content_size)); |
| 91 gfx::Rect content_rect = total_content_rect; | 89 gfx::Rect content_rect = total_content_rect; |
| 92 content_rect.Intersect(canvas_rect); | 90 content_rect.Intersect(canvas_rect); |
| 93 | 91 |
| 94 // Clear one texel inside the right/bottom edge of the content rect, | |
| 95 // as it may only be partially covered by the picture playback. | |
| 96 // Also clear one texel outside the right/bottom edge of the content rect, | |
| 97 // as it may get blended in by linear filtering when zoomed in. | |
| 98 gfx::Rect deflated_content_rect = total_content_rect; | |
| 99 deflated_content_rect.Inset(0, 0, 1, 1); | |
| 100 | |
| 101 gfx::Rect canvas_outside_content_rect = canvas_rect; | |
| 102 canvas_outside_content_rect.Subtract(deflated_content_rect); | |
| 103 | |
| 104 if (!canvas_outside_content_rect.IsEmpty()) { | |
| 105 gfx::Rect inflated_content_rect = total_content_rect; | |
| 106 inflated_content_rect.Inset(0, 0, -1, -1); | |
| 107 canvas->clipRect(gfx::RectToSkRect(inflated_content_rect), | |
| 108 SkRegion::kReplace_Op); | |
| 109 canvas->clipRect(gfx::RectToSkRect(deflated_content_rect), | |
| 110 SkRegion::kDifference_Op); | |
| 111 canvas->drawColor(background_color_, SkXfermode::kSrc_Mode); | |
| 112 } | |
| 113 | |
| 114 // Rasterize the collection of relevant picture piles. | 92 // Rasterize the collection of relevant picture piles. |
| 115 gfx::Rect layer_rect = gfx::ToEnclosingRect( | 93 gfx::Rect layer_rect = gfx::ToEnclosingRect( |
| 116 gfx::ScaleRect(content_rect, 1.f / contents_scale)); | 94 gfx::ScaleRect(content_rect, 1.f / contents_scale)); |
| 117 | 95 |
| 118 canvas->clipRect(gfx::RectToSkRect(content_rect), | 96 canvas->clipRect(gfx::RectToSkRect(content_rect), |
| 119 SkRegion::kReplace_Op); | 97 SkRegion::kIntersect_Op); |
| 120 Region unclipped(content_rect); | 98 Region unclipped(content_rect); |
| 121 | 99 |
| 122 if (raster_stats) { | 100 if (raster_stats) { |
| 123 raster_stats->total_pixels_rasterized = 0; | 101 raster_stats->total_pixels_rasterized = 0; |
| 124 raster_stats->total_rasterize_time = base::TimeDelta::FromSeconds(0); | 102 raster_stats->total_rasterize_time = base::TimeDelta::FromSeconds(0); |
| 125 raster_stats->best_rasterize_time = base::TimeDelta::FromSeconds(0); | 103 raster_stats->best_rasterize_time = base::TimeDelta::FromSeconds(0); |
| 126 } | 104 } |
| 127 | 105 |
| 128 for (TilingData::Iterator tile_iter(&tiling_, layer_rect); | 106 for (TilingData::Iterator tile_iter(&tiling_, layer_rect); |
| 129 tile_iter; ++tile_iter) { | 107 tile_iter; ++tile_iter) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 // distinguish between non painted areas and problems with missing | 188 // distinguish between non painted areas and problems with missing |
| 211 // pictures. | 189 // pictures. |
| 212 SkPaint paint; | 190 SkPaint paint; |
| 213 paint.setColor(DebugColors::MissingPictureFillColor()); | 191 paint.setColor(DebugColors::MissingPictureFillColor()); |
| 214 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 192 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 215 canvas->drawPaint(paint); | 193 canvas->drawPaint(paint); |
| 216 #endif // NDEBUG | 194 #endif // NDEBUG |
| 217 | 195 |
| 218 // We should always paint some part of |content_rect|. | 196 // We should always paint some part of |content_rect|. |
| 219 DCHECK(!unclipped.Contains(content_rect)); | 197 DCHECK(!unclipped.Contains(content_rect)); |
| 198 } | |
| 199 | |
| 200 void PicturePileImpl::RasterToBitmap( | |
| 201 SkCanvas* canvas, | |
| 202 gfx::Rect canvas_rect, | |
| 203 float contents_scale, | |
| 204 RasterStats* raster_stats) { | |
| 205 | |
| 206 canvas->save(); | |
| 207 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); | |
| 208 | |
| 209 gfx::SizeF total_content_size = gfx::ScaleSize(tiling_.total_size(), | |
| 210 contents_scale); | |
| 211 gfx::Rect total_content_rect(gfx::ToCeiledSize(total_content_size)); | |
| 212 gfx::Rect content_rect = total_content_rect; | |
| 213 content_rect.Intersect(canvas_rect); | |
| 214 | |
| 215 #ifndef NDEBUG | |
| 216 // Any non-painted areas will be left in this color. | |
| 217 canvas->clear(DebugColors::NonPaintedFillColor()); | |
| 218 #endif // NDEBUG | |
| 219 | |
| 220 // TODO(enne): this needs to be rolled together with the border clear | |
| 221 SkPaint paint; | |
| 222 paint.setAntiAlias(false); | |
| 223 paint.setXfermodeMode(SkXfermode::kClear_Mode); | |
| 224 canvas->drawRect(gfx::RectToSkRect(content_rect), paint); | |
| 225 | |
| 226 // Clear one texel inside the right/bottom edge of the content rect, | |
| 227 // as it may only be partially covered by the picture playback. | |
| 228 // Also clear one texel outside the right/bottom edge of the content rect, | |
| 229 // as it may get blended in by linear filtering when zoomed in. | |
| 230 gfx::Rect deflated_content_rect = total_content_rect; | |
| 231 deflated_content_rect.Inset(0, 0, 1, 1); | |
| 232 | |
| 233 gfx::Rect canvas_outside_content_rect = canvas_rect; | |
| 234 canvas_outside_content_rect.Subtract(deflated_content_rect); | |
| 235 | |
| 236 if (!canvas_outside_content_rect.IsEmpty()) { | |
| 237 gfx::Rect inflated_content_rect = total_content_rect; | |
| 238 inflated_content_rect.Inset(0, 0, -1, -1); | |
| 239 canvas->clipRect(gfx::RectToSkRect(inflated_content_rect), | |
| 240 SkRegion::kReplace_Op); | |
| 241 canvas->clipRect(gfx::RectToSkRect(deflated_content_rect), | |
| 242 SkRegion::kDifference_Op); | |
| 243 canvas->drawColor(background_color_, SkXfermode::kSrc_Mode); | |
| 244 } | |
| 220 | 245 |
| 221 canvas->restore(); | 246 canvas->restore(); |
| 247 | |
| 248 RasterDirect(canvas, canvas_rect, contents_scale, raster_stats); | |
| 222 } | 249 } |
| 223 | 250 |
| 224 skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() { | 251 skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() { |
| 225 TRACE_EVENT0("cc", "PicturePileImpl::GetFlattenedPicture"); | 252 TRACE_EVENT0("cc", "PicturePileImpl::GetFlattenedPicture"); |
| 226 | 253 |
| 227 gfx::Rect layer_rect(tiling_.total_size()); | 254 gfx::Rect layer_rect(tiling_.total_size()); |
| 228 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); | 255 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); |
| 229 if (layer_rect.IsEmpty()) | 256 if (layer_rect.IsEmpty()) |
| 230 return picture; | 257 return picture; |
| 231 | 258 |
| 232 SkCanvas* canvas = picture->beginRecording( | 259 SkCanvas* canvas = picture->beginRecording( |
| 233 layer_rect.width(), | 260 layer_rect.width(), |
| 234 layer_rect.height(), | 261 layer_rect.height(), |
| 235 SkPicture::kUsePathBoundsForClip_RecordingFlag); | 262 SkPicture::kUsePathBoundsForClip_RecordingFlag); |
| 236 | 263 |
| 237 Raster(canvas, layer_rect, 1.0, NULL); | 264 RasterDirect(canvas, layer_rect, 1.0, NULL); |
|
danakj
2013/05/16 15:17:55
I'm a little unsure about this change and 288. Can
enne (OOO)
2013/05/16 20:34:11
This path is going away in like the next week. Ho
| |
| 238 picture->endRecording(); | 265 picture->endRecording(); |
| 239 | 266 |
| 240 return picture; | 267 return picture; |
| 241 } | 268 } |
| 242 | 269 |
| 243 void PicturePileImpl::AnalyzeInRect(gfx::Rect content_rect, | 270 void PicturePileImpl::AnalyzeInRect(gfx::Rect content_rect, |
| 244 float contents_scale, | 271 float contents_scale, |
| 245 PicturePileImpl::Analysis* analysis) { | 272 PicturePileImpl::Analysis* analysis) { |
| 246 DCHECK(analysis); | 273 DCHECK(analysis); |
| 247 TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect"); | 274 TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect"); |
| 248 | 275 |
| 249 gfx::Rect layer_rect = gfx::ToEnclosingRect( | 276 gfx::Rect layer_rect = gfx::ToEnclosingRect( |
| 250 gfx::ScaleRect(content_rect, 1.0f / contents_scale)); | 277 gfx::ScaleRect(content_rect, 1.0f / contents_scale)); |
| 251 | 278 |
| 252 layer_rect.Intersect(gfx::Rect(tiling_.total_size())); | 279 layer_rect.Intersect(gfx::Rect(tiling_.total_size())); |
| 253 | 280 |
| 254 SkBitmap empty_bitmap; | 281 SkBitmap empty_bitmap; |
| 255 empty_bitmap.setConfig(SkBitmap::kNo_Config, | 282 empty_bitmap.setConfig(SkBitmap::kNo_Config, |
| 256 layer_rect.width(), | 283 layer_rect.width(), |
| 257 layer_rect.height()); | 284 layer_rect.height()); |
| 258 skia::AnalysisDevice device(empty_bitmap); | 285 skia::AnalysisDevice device(empty_bitmap); |
| 259 skia::AnalysisCanvas canvas(&device); | 286 skia::AnalysisCanvas canvas(&device); |
| 260 | 287 |
| 261 Raster(&canvas, layer_rect, 1.0f, NULL); | 288 RasterDirect(&canvas, layer_rect, 1.0f, NULL); |
|
danakj
2013/05/16 15:17:55
Say you have a tile that has nothing in it. When w
enne (OOO)
2013/05/16 20:34:11
Added a test, ccing vmpstr.
| |
| 262 | 289 |
| 263 analysis->is_solid_color = canvas.getColorIfSolid(&analysis->solid_color); | 290 analysis->is_solid_color = canvas.getColorIfSolid(&analysis->solid_color); |
| 264 analysis->has_text = canvas.hasText(); | 291 analysis->has_text = canvas.hasText(); |
| 265 } | 292 } |
| 266 | 293 |
| 267 PicturePileImpl::Analysis::Analysis() | 294 PicturePileImpl::Analysis::Analysis() |
| 268 : is_solid_color(false), | 295 : is_solid_color(false), |
| 269 has_text(false) { | 296 has_text(false) { |
| 270 } | 297 } |
| 271 | 298 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 layer_rect_, | 354 layer_rect_, |
| 328 *picture_list_iterator_); | 355 *picture_list_iterator_); |
| 329 if (pixel_ref_iterator_) | 356 if (pixel_ref_iterator_) |
| 330 return; | 357 return; |
| 331 } | 358 } |
| 332 ++tile_iterator_; | 359 ++tile_iterator_; |
| 333 } while (AdvanceToTileWithPictures()); | 360 } while (AdvanceToTileWithPictures()); |
| 334 } | 361 } |
| 335 | 362 |
| 336 } // namespace cc | 363 } // namespace cc |
| OLD | NEW |