| 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_tree_impl()->RegisterPictureLayerImpl(this); | 67 layer_tree_impl()->RegisterPictureLayerImpl(this); |
| 69 } | 68 } |
| 70 | 69 |
| 71 PictureLayerImpl::~PictureLayerImpl() { | 70 PictureLayerImpl::~PictureLayerImpl() { |
| 72 layer_tree_impl()->UnregisterPictureLayerImpl(this); | 71 layer_tree_impl()->UnregisterPictureLayerImpl(this); |
| 73 } | 72 } |
| 74 | 73 |
| 75 const char* PictureLayerImpl::LayerTypeAsString() const { | 74 const char* PictureLayerImpl::LayerTypeAsString() const { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 114 |
| 116 layer_impl->tilings_->SetClient(layer_impl); | 115 layer_impl->tilings_->SetClient(layer_impl); |
| 117 if (tilings_) | 116 if (tilings_) |
| 118 tilings_->SetClient(this); | 117 tilings_->SetClient(this); |
| 119 | 118 |
| 120 layer_impl->raster_page_scale_ = raster_page_scale_; | 119 layer_impl->raster_page_scale_ = raster_page_scale_; |
| 121 layer_impl->raster_device_scale_ = raster_device_scale_; | 120 layer_impl->raster_device_scale_ = raster_device_scale_; |
| 122 layer_impl->raster_source_scale_ = raster_source_scale_; | 121 layer_impl->raster_source_scale_ = raster_source_scale_; |
| 123 layer_impl->raster_contents_scale_ = raster_contents_scale_; | 122 layer_impl->raster_contents_scale_ = raster_contents_scale_; |
| 124 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; | 123 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; |
| 125 | |
| 126 layer_impl->UpdateLCDTextStatus(is_using_lcd_text_); | |
| 127 layer_impl->needs_post_commit_initialization_ = false; | 124 layer_impl->needs_post_commit_initialization_ = false; |
| 128 | 125 |
| 129 // The invalidation on this soon-to-be-recycled layer must be cleared to | 126 // The invalidation on this soon-to-be-recycled layer must be cleared to |
| 130 // mirror clearing the invalidation in PictureLayer's version of this function | 127 // mirror clearing the invalidation in PictureLayer's version of this function |
| 131 // in case push properties is skipped. | 128 // in case push properties is skipped. |
| 132 layer_impl->invalidation_.Swap(&invalidation_); | 129 layer_impl->invalidation_.Swap(&invalidation_); |
| 133 invalidation_.Clear(); | 130 invalidation_.Clear(); |
| 134 needs_post_commit_initialization_ = true; | 131 needs_post_commit_initialization_ = true; |
| 135 | 132 |
| 136 // We always need to push properties. | 133 // We always need to push properties. |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 392 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
| 396 if (tilings_->tiling_at(i)->NeedsUpdateForFrameAtTime( | 393 if (tilings_->tiling_at(i)->NeedsUpdateForFrameAtTime( |
| 397 current_frame_time_in_seconds)) { | 394 current_frame_time_in_seconds)) { |
| 398 tiling_needs_update = true; | 395 tiling_needs_update = true; |
| 399 break; | 396 break; |
| 400 } | 397 } |
| 401 } | 398 } |
| 402 if (!tiling_needs_update) | 399 if (!tiling_needs_update) |
| 403 return; | 400 return; |
| 404 | 401 |
| 405 UpdateLCDTextStatus(can_use_lcd_text()); | |
| 406 | |
| 407 // Use visible_content_rect, unless it's empty. If it's empty, then | 402 // Use visible_content_rect, unless it's empty. If it's empty, then |
| 408 // try to inverse project the viewport into layer space and use that. | 403 // try to inverse project the viewport into layer space and use that. |
| 409 gfx::Rect visible_rect_in_content_space = visible_rect_for_tile_priority_; | 404 gfx::Rect visible_rect_in_content_space = visible_rect_for_tile_priority_; |
| 410 if (visible_rect_in_content_space.IsEmpty()) { | 405 if (visible_rect_in_content_space.IsEmpty()) { |
| 411 gfx::Transform screen_to_layer(gfx::Transform::kSkipInitialization); | 406 gfx::Transform screen_to_layer(gfx::Transform::kSkipInitialization); |
| 412 if (screen_space_transform_for_tile_priority_.GetInverse( | 407 if (screen_space_transform_for_tile_priority_.GetInverse( |
| 413 &screen_to_layer)) { | 408 &screen_to_layer)) { |
| 414 visible_rect_in_content_space = | 409 visible_rect_in_content_space = |
| 415 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 410 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
| 416 screen_to_layer, gfx::Rect(viewport_size_for_tile_priority_))); | 411 screen_to_layer, gfx::Rect(viewport_size_for_tile_priority_))); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { | 529 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { |
| 535 return pile_->GetFlattenedPicture(); | 530 return pile_->GetFlattenedPicture(); |
| 536 } | 531 } |
| 537 | 532 |
| 538 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, | 533 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, |
| 539 const gfx::Rect& content_rect) { | 534 const gfx::Rect& content_rect) { |
| 540 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) | 535 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) |
| 541 return scoped_refptr<Tile>(); | 536 return scoped_refptr<Tile>(); |
| 542 | 537 |
| 543 int flags = 0; | 538 int flags = 0; |
| 544 if (is_using_lcd_text_) | |
| 545 flags |= Tile::USE_LCD_TEXT; | |
| 546 | |
| 547 // We analyze picture before rasterization to detect solid-color tiles. | 539 // We analyze picture before rasterization to detect solid-color tiles. |
| 548 // If the tile is detected as such there is no need to raster or upload. | 540 // If the tile is detected as such there is no need to raster or upload. |
| 549 // It is drawn directly as a solid-color quad saving memory, raster and upload | 541 // It is drawn directly as a solid-color quad saving memory, raster and upload |
| 550 // cost. The analysis step is however expensive and may not be justified when | 542 // cost. The analysis step is however expensive and may not be justified when |
| 551 // doing gpu rasterization which runs on the compositor thread and where there | 543 // doing gpu rasterization which runs on the compositor thread and where there |
| 552 // is no upload. | 544 // is no upload. |
| 553 // TODO(alokp): Revisit the decision to avoid analysis for gpu rasterization | 545 // TODO(alokp): Revisit the decision to avoid analysis for gpu rasterization |
| 554 // becuase it too can potentially benefit from memory savings. | 546 // becuase it too can potentially benefit from memory savings. |
| 555 if (!layer_tree_impl()->use_gpu_rasterization()) { | 547 if (!layer_tree_impl()->use_gpu_rasterization()) { |
| 556 // Additionally, we do not want to do the analysis if the layer is too | 548 // 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... |
| 671 return gfx::Size(width, height); | 663 return gfx::Size(width, height); |
| 672 } | 664 } |
| 673 | 665 |
| 674 return default_tile_size; | 666 return default_tile_size; |
| 675 } | 667 } |
| 676 | 668 |
| 677 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { | 669 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { |
| 678 DCHECK(!other->needs_post_commit_initialization_); | 670 DCHECK(!other->needs_post_commit_initialization_); |
| 679 DCHECK(other->tilings_); | 671 DCHECK(other->tilings_); |
| 680 | 672 |
| 681 UpdateLCDTextStatus(other->is_using_lcd_text_); | |
| 682 | |
| 683 if (!DrawsContent()) { | 673 if (!DrawsContent()) { |
| 684 RemoveAllTilings(); | 674 RemoveAllTilings(); |
| 685 return; | 675 return; |
| 686 } | 676 } |
| 687 | 677 |
| 688 raster_page_scale_ = other->raster_page_scale_; | 678 raster_page_scale_ = other->raster_page_scale_; |
| 689 raster_device_scale_ = other->raster_device_scale_; | 679 raster_device_scale_ = other->raster_device_scale_; |
| 690 raster_source_scale_ = other->raster_source_scale_; | 680 raster_source_scale_ = other->raster_source_scale_; |
| 691 raster_contents_scale_ = other->raster_contents_scale_; | 681 raster_contents_scale_ = other->raster_contents_scale_; |
| 692 low_res_raster_contents_scale_ = other->low_res_raster_contents_scale_; | 682 low_res_raster_contents_scale_ = other->low_res_raster_contents_scale_; |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 // then it will end up having less than one pixel of content in that | 1268 // then it will end up having less than one pixel of content in that |
| 1279 // dimension. Bump the minimum contents scale up in this case to prevent | 1269 // dimension. Bump the minimum contents scale up in this case to prevent |
| 1280 // this from happening. | 1270 // this from happening. |
| 1281 int min_dimension = std::min(bounds().width(), bounds().height()); | 1271 int min_dimension = std::min(bounds().width(), bounds().height()); |
| 1282 if (!min_dimension) | 1272 if (!min_dimension) |
| 1283 return setting_min; | 1273 return setting_min; |
| 1284 | 1274 |
| 1285 return std::max(1.f / min_dimension, setting_min); | 1275 return std::max(1.f / min_dimension, setting_min); |
| 1286 } | 1276 } |
| 1287 | 1277 |
| 1288 void PictureLayerImpl::UpdateLCDTextStatus(bool new_status) { | |
| 1289 // Once this layer is not using lcd text, don't switch back. | |
| 1290 if (!is_using_lcd_text_) | |
| 1291 return; | |
| 1292 | |
| 1293 if (is_using_lcd_text_ == new_status) | |
| 1294 return; | |
| 1295 | |
| 1296 is_using_lcd_text_ = new_status; | |
| 1297 tilings_->SetCanUseLCDText(is_using_lcd_text_); | |
| 1298 } | |
| 1299 | |
| 1300 void PictureLayerImpl::ResetRasterScale() { | 1278 void PictureLayerImpl::ResetRasterScale() { |
| 1301 raster_page_scale_ = 0.f; | 1279 raster_page_scale_ = 0.f; |
| 1302 raster_device_scale_ = 0.f; | 1280 raster_device_scale_ = 0.f; |
| 1303 raster_source_scale_ = 0.f; | 1281 raster_source_scale_ = 0.f; |
| 1304 raster_contents_scale_ = 0.f; | 1282 raster_contents_scale_ = 0.f; |
| 1305 low_res_raster_contents_scale_ = 0.f; | 1283 low_res_raster_contents_scale_ = 0.f; |
| 1306 raster_source_scale_is_fixed_ = false; | 1284 raster_source_scale_is_fixed_ = false; |
| 1307 | 1285 |
| 1308 // When raster scales aren't valid, don't update tile priorities until | 1286 // When raster scales aren't valid, don't update tile priorities until |
| 1309 // this layer has been updated via UpdateDrawProperties. | 1287 // this layer has been updated via UpdateDrawProperties. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 ++iter) { | 1344 ++iter) { |
| 1367 scoped_ptr<base::DictionaryValue> tile_data(new base::DictionaryValue); | 1345 scoped_ptr<base::DictionaryValue> tile_data(new base::DictionaryValue); |
| 1368 tile_data->Set("geometry_rect", | 1346 tile_data->Set("geometry_rect", |
| 1369 MathUtil::AsValue(iter.geometry_rect()).release()); | 1347 MathUtil::AsValue(iter.geometry_rect()).release()); |
| 1370 if (*iter) | 1348 if (*iter) |
| 1371 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release()); | 1349 tile_data->Set("tile", TracedValue::CreateIDRef(*iter).release()); |
| 1372 | 1350 |
| 1373 coverage_tiles->Append(tile_data.release()); | 1351 coverage_tiles->Append(tile_data.release()); |
| 1374 } | 1352 } |
| 1375 state->Set("coverage_tiles", coverage_tiles.release()); | 1353 state->Set("coverage_tiles", coverage_tiles.release()); |
| 1376 state->SetBoolean("is_using_lcd_text", is_using_lcd_text_); | |
| 1377 } | 1354 } |
| 1378 | 1355 |
| 1379 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { | 1356 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { |
| 1380 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); | 1357 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); |
| 1381 return tilings_->GPUMemoryUsageInBytes(); | 1358 return tilings_->GPUMemoryUsageInBytes(); |
| 1382 } | 1359 } |
| 1383 | 1360 |
| 1384 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { | 1361 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { |
| 1385 benchmark->RunOnLayer(this); | 1362 benchmark->RunOnLayer(this); |
| 1386 } | 1363 } |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1650 return iterator_index_ < iterators_.size(); | 1627 return iterator_index_ < iterators_.size(); |
| 1651 } | 1628 } |
| 1652 | 1629 |
| 1653 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( | 1630 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( |
| 1654 PictureLayerTiling::TilingEvictionTileIterator* it) const { | 1631 PictureLayerTiling::TilingEvictionTileIterator* it) const { |
| 1655 return it->get_type() == iteration_stage_ && | 1632 return it->get_type() == iteration_stage_ && |
| 1656 (**it)->required_for_activation() == required_for_activation_; | 1633 (**it)->required_for_activation() == required_for_activation_; |
| 1657 } | 1634 } |
| 1658 | 1635 |
| 1659 } // namespace cc | 1636 } // namespace cc |
| OLD | NEW |