| 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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 ideal_device_scale_(0.f), | 55 ideal_device_scale_(0.f), |
| 56 ideal_source_scale_(0.f), | 56 ideal_source_scale_(0.f), |
| 57 ideal_contents_scale_(0.f), | 57 ideal_contents_scale_(0.f), |
| 58 raster_page_scale_(0.f), | 58 raster_page_scale_(0.f), |
| 59 raster_device_scale_(0.f), | 59 raster_device_scale_(0.f), |
| 60 raster_source_scale_(0.f), | 60 raster_source_scale_(0.f), |
| 61 raster_contents_scale_(0.f), | 61 raster_contents_scale_(0.f), |
| 62 low_res_raster_contents_scale_(0.f), | 62 low_res_raster_contents_scale_(0.f), |
| 63 raster_source_scale_is_fixed_(false), | 63 raster_source_scale_is_fixed_(false), |
| 64 was_animating_transform_to_screen_(false), | 64 was_animating_transform_to_screen_(false), |
| 65 is_using_lcd_text_(tree_impl->settings().can_use_lcd_text), | |
| 66 needs_post_commit_initialization_(true), | 65 needs_post_commit_initialization_(true), |
| 67 should_update_tile_priorities_(false), | 66 should_update_tile_priorities_(false), |
| 68 layer_needs_to_register_itself_(true) { | 67 layer_needs_to_register_itself_(true) { |
| 69 } | 68 } |
| 70 | 69 |
| 71 PictureLayerImpl::~PictureLayerImpl() { | 70 PictureLayerImpl::~PictureLayerImpl() { |
| 72 if (!layer_needs_to_register_itself_) | 71 if (!layer_needs_to_register_itself_) |
| 73 layer_tree_impl()->tile_manager()->UnregisterPictureLayerImpl(this); | 72 layer_tree_impl()->tile_manager()->UnregisterPictureLayerImpl(this); |
| 74 } | 73 } |
| 75 | 74 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 115 |
| 117 layer_impl->tilings_->SetClient(layer_impl); | 116 layer_impl->tilings_->SetClient(layer_impl); |
| 118 if (tilings_) | 117 if (tilings_) |
| 119 tilings_->SetClient(this); | 118 tilings_->SetClient(this); |
| 120 | 119 |
| 121 layer_impl->raster_page_scale_ = raster_page_scale_; | 120 layer_impl->raster_page_scale_ = raster_page_scale_; |
| 122 layer_impl->raster_device_scale_ = raster_device_scale_; | 121 layer_impl->raster_device_scale_ = raster_device_scale_; |
| 123 layer_impl->raster_source_scale_ = raster_source_scale_; | 122 layer_impl->raster_source_scale_ = raster_source_scale_; |
| 124 layer_impl->raster_contents_scale_ = raster_contents_scale_; | 123 layer_impl->raster_contents_scale_ = raster_contents_scale_; |
| 125 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; | 124 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; |
| 126 | |
| 127 layer_impl->UpdateLCDTextStatus(is_using_lcd_text_); | |
| 128 layer_impl->needs_post_commit_initialization_ = false; | 125 layer_impl->needs_post_commit_initialization_ = false; |
| 129 | 126 |
| 130 // The invalidation on this soon-to-be-recycled layer must be cleared to | 127 // The invalidation on this soon-to-be-recycled layer must be cleared to |
| 131 // mirror clearing the invalidation in PictureLayer's version of this function | 128 // mirror clearing the invalidation in PictureLayer's version of this function |
| 132 // in case push properties is skipped. | 129 // in case push properties is skipped. |
| 133 layer_impl->invalidation_.Swap(&invalidation_); | 130 layer_impl->invalidation_.Swap(&invalidation_); |
| 134 invalidation_.Clear(); | 131 invalidation_.Clear(); |
| 135 needs_post_commit_initialization_ = true; | 132 needs_post_commit_initialization_ = true; |
| 136 | 133 |
| 137 // We always need to push properties. | 134 // We always need to push properties. |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 404 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
| 408 if (tilings_->tiling_at(i)->NeedsUpdateForFrameAtTime( | 405 if (tilings_->tiling_at(i)->NeedsUpdateForFrameAtTime( |
| 409 current_frame_time_in_seconds)) { | 406 current_frame_time_in_seconds)) { |
| 410 tiling_needs_update = true; | 407 tiling_needs_update = true; |
| 411 break; | 408 break; |
| 412 } | 409 } |
| 413 } | 410 } |
| 414 if (!tiling_needs_update) | 411 if (!tiling_needs_update) |
| 415 return; | 412 return; |
| 416 | 413 |
| 417 UpdateLCDTextStatus(can_use_lcd_text()); | |
| 418 | |
| 419 // Use visible_content_rect, unless it's empty. If it's empty, then | 414 // Use visible_content_rect, unless it's empty. If it's empty, then |
| 420 // try to inverse project the viewport into layer space and use that. | 415 // try to inverse project the viewport into layer space and use that. |
| 421 gfx::Rect visible_rect_in_content_space = visible_rect_for_tile_priority_; | 416 gfx::Rect visible_rect_in_content_space = visible_rect_for_tile_priority_; |
| 422 if (visible_rect_in_content_space.IsEmpty()) { | 417 if (visible_rect_in_content_space.IsEmpty()) { |
| 423 gfx::Transform screen_to_layer(gfx::Transform::kSkipInitialization); | 418 gfx::Transform screen_to_layer(gfx::Transform::kSkipInitialization); |
| 424 if (screen_space_transform_for_tile_priority_.GetInverse( | 419 if (screen_space_transform_for_tile_priority_.GetInverse( |
| 425 &screen_to_layer)) { | 420 &screen_to_layer)) { |
| 426 visible_rect_in_content_space = | 421 visible_rect_in_content_space = |
| 427 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 422 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
| 428 screen_to_layer, gfx::Rect(viewport_size_for_tile_priority_))); | 423 screen_to_layer, gfx::Rect(viewport_size_for_tile_priority_))); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { | 541 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { |
| 547 return pile_->GetFlattenedPicture(); | 542 return pile_->GetFlattenedPicture(); |
| 548 } | 543 } |
| 549 | 544 |
| 550 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, | 545 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, |
| 551 const gfx::Rect& content_rect) { | 546 const gfx::Rect& content_rect) { |
| 552 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) | 547 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) |
| 553 return scoped_refptr<Tile>(); | 548 return scoped_refptr<Tile>(); |
| 554 | 549 |
| 555 int flags = 0; | 550 int flags = 0; |
| 556 if (is_using_lcd_text_) | |
| 557 flags |= Tile::USE_LCD_TEXT; | |
| 558 | |
| 559 // We analyze picture before rasterization to detect solid-color tiles. | 551 // We analyze picture before rasterization to detect solid-color tiles. |
| 560 // If the tile is detected as such there is no need to raster or upload. | 552 // If the tile is detected as such there is no need to raster or upload. |
| 561 // It is drawn directly as a solid-color quad saving memory, raster and upload | 553 // It is drawn directly as a solid-color quad saving memory, raster and upload |
| 562 // cost. The analysis step is however expensive and may not be justified when | 554 // cost. The analysis step is however expensive and may not be justified when |
| 563 // doing gpu rasterization which runs on the compositor thread and where there | 555 // doing gpu rasterization which runs on the compositor thread and where there |
| 564 // is no upload. | 556 // is no upload. |
| 565 // TODO(alokp): Revisit the decision to avoid analysis for gpu rasterization | 557 // TODO(alokp): Revisit the decision to avoid analysis for gpu rasterization |
| 566 // becuase it too can potentially benefit from memory savings. | 558 // becuase it too can potentially benefit from memory savings. |
| 567 if (!layer_tree_impl()->use_gpu_rasterization()) { | 559 if (!layer_tree_impl()->use_gpu_rasterization()) { |
| 568 // Additionally, we do not want to do the analysis if the layer is too | 560 // Additionally, we do not want to do the analysis if the layer is too |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 return gfx::Size(width, height); | 675 return gfx::Size(width, height); |
| 684 } | 676 } |
| 685 | 677 |
| 686 return default_tile_size; | 678 return default_tile_size; |
| 687 } | 679 } |
| 688 | 680 |
| 689 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { | 681 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { |
| 690 DCHECK(!other->needs_post_commit_initialization_); | 682 DCHECK(!other->needs_post_commit_initialization_); |
| 691 DCHECK(other->tilings_); | 683 DCHECK(other->tilings_); |
| 692 | 684 |
| 693 UpdateLCDTextStatus(other->is_using_lcd_text_); | |
| 694 | |
| 695 if (!DrawsContent()) { | 685 if (!DrawsContent()) { |
| 696 RemoveAllTilings(); | 686 RemoveAllTilings(); |
| 697 return; | 687 return; |
| 698 } | 688 } |
| 699 | 689 |
| 700 raster_page_scale_ = other->raster_page_scale_; | 690 raster_page_scale_ = other->raster_page_scale_; |
| 701 raster_device_scale_ = other->raster_device_scale_; | 691 raster_device_scale_ = other->raster_device_scale_; |
| 702 raster_source_scale_ = other->raster_source_scale_; | 692 raster_source_scale_ = other->raster_source_scale_; |
| 703 raster_contents_scale_ = other->raster_contents_scale_; | 693 raster_contents_scale_ = other->raster_contents_scale_; |
| 704 low_res_raster_contents_scale_ = other->low_res_raster_contents_scale_; | 694 low_res_raster_contents_scale_ = other->low_res_raster_contents_scale_; |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 // then it will end up having less than one pixel of content in that | 1267 // then it will end up having less than one pixel of content in that |
| 1278 // dimension. Bump the minimum contents scale up in this case to prevent | 1268 // dimension. Bump the minimum contents scale up in this case to prevent |
| 1279 // this from happening. | 1269 // this from happening. |
| 1280 int min_dimension = std::min(bounds().width(), bounds().height()); | 1270 int min_dimension = std::min(bounds().width(), bounds().height()); |
| 1281 if (!min_dimension) | 1271 if (!min_dimension) |
| 1282 return setting_min; | 1272 return setting_min; |
| 1283 | 1273 |
| 1284 return std::max(1.f / min_dimension, setting_min); | 1274 return std::max(1.f / min_dimension, setting_min); |
| 1285 } | 1275 } |
| 1286 | 1276 |
| 1287 void PictureLayerImpl::UpdateLCDTextStatus(bool new_status) { | |
| 1288 // Once this layer is not using lcd text, don't switch back. | |
| 1289 if (!is_using_lcd_text_) | |
| 1290 return; | |
| 1291 | |
| 1292 if (is_using_lcd_text_ == new_status) | |
| 1293 return; | |
| 1294 | |
| 1295 is_using_lcd_text_ = new_status; | |
| 1296 tilings_->SetCanUseLCDText(is_using_lcd_text_); | |
| 1297 } | |
| 1298 | |
| 1299 void PictureLayerImpl::ResetRasterScale() { | 1277 void PictureLayerImpl::ResetRasterScale() { |
| 1300 raster_page_scale_ = 0.f; | 1278 raster_page_scale_ = 0.f; |
| 1301 raster_device_scale_ = 0.f; | 1279 raster_device_scale_ = 0.f; |
| 1302 raster_source_scale_ = 0.f; | 1280 raster_source_scale_ = 0.f; |
| 1303 raster_contents_scale_ = 0.f; | 1281 raster_contents_scale_ = 0.f; |
| 1304 low_res_raster_contents_scale_ = 0.f; | 1282 low_res_raster_contents_scale_ = 0.f; |
| 1305 raster_source_scale_is_fixed_ = false; | 1283 raster_source_scale_is_fixed_ = false; |
| 1306 | 1284 |
| 1307 // When raster scales aren't valid, don't update tile priorities until | 1285 // When raster scales aren't valid, don't update tile priorities until |
| 1308 // this layer has been updated via UpdateDrawProperties. | 1286 // this layer has been updated via UpdateDrawProperties. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 ++iter) { | 1343 ++iter) { |
| 1366 scoped_ptr<base::DictionaryValue> tile_data(new base::DictionaryValue); | 1344 scoped_ptr<base::DictionaryValue> tile_data(new base::DictionaryValue); |
| 1367 tile_data->Set("geometry_rect", | 1345 tile_data->Set("geometry_rect", |
| 1368 MathUtil::AsValue(iter.geometry_rect()).release()); | 1346 MathUtil::AsValue(iter.geometry_rect()).release()); |
| 1369 if (*iter) | 1347 if (*iter) |
| 1370 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release()); | 1348 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release()); |
| 1371 | 1349 |
| 1372 coverage_tiles->Append(tile_data.release()); | 1350 coverage_tiles->Append(tile_data.release()); |
| 1373 } | 1351 } |
| 1374 state->Set("coverage_tiles", coverage_tiles.release()); | 1352 state->Set("coverage_tiles", coverage_tiles.release()); |
| 1375 state->SetBoolean("is_using_lcd_text", is_using_lcd_text_); | |
| 1376 } | 1353 } |
| 1377 | 1354 |
| 1378 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { | 1355 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { |
| 1379 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); | 1356 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); |
| 1380 return tilings_->GPUMemoryUsageInBytes(); | 1357 return tilings_->GPUMemoryUsageInBytes(); |
| 1381 } | 1358 } |
| 1382 | 1359 |
| 1383 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { | 1360 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { |
| 1384 benchmark->RunOnLayer(this); | 1361 benchmark->RunOnLayer(this); |
| 1385 } | 1362 } |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1639 return iterator_index_ < iterators_.size(); | 1616 return iterator_index_ < iterators_.size(); |
| 1640 } | 1617 } |
| 1641 | 1618 |
| 1642 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( | 1619 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( |
| 1643 PictureLayerTiling::TilingEvictionTileIterator* it) const { | 1620 PictureLayerTiling::TilingEvictionTileIterator* it) const { |
| 1644 return it->get_type() == iteration_stage_ && | 1621 return it->get_type() == iteration_stage_ && |
| 1645 (**it)->required_for_activation() == required_for_activation_; | 1622 (**it)->required_for_activation() == required_for_activation_; |
| 1646 } | 1623 } |
| 1647 | 1624 |
| 1648 } // namespace cc | 1625 } // namespace cc |
| OLD | NEW |