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 "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 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 ideal_source_scale_(0.f), | 68 ideal_source_scale_(0.f), |
| 69 ideal_contents_scale_(0.f), | 69 ideal_contents_scale_(0.f), |
| 70 raster_page_scale_(0.f), | 70 raster_page_scale_(0.f), |
| 71 raster_device_scale_(0.f), | 71 raster_device_scale_(0.f), |
| 72 raster_source_scale_(0.f), | 72 raster_source_scale_(0.f), |
| 73 raster_contents_scale_(0.f), | 73 raster_contents_scale_(0.f), |
| 74 low_res_raster_contents_scale_(0.f), | 74 low_res_raster_contents_scale_(0.f), |
| 75 raster_source_scale_is_fixed_(false), | 75 raster_source_scale_is_fixed_(false), |
| 76 was_screen_space_transform_animating_(false), | 76 was_screen_space_transform_animating_(false), |
| 77 needs_post_commit_initialization_(true), | 77 needs_post_commit_initialization_(true), |
| 78 should_update_tile_priorities_(false) { | 78 should_update_tile_priorities_(false), |
| 79 is_solid_color_(false), | |
| 80 solid_color_(SK_ColorBLACK) { | |
| 79 layer_tree_impl()->RegisterPictureLayerImpl(this); | 81 layer_tree_impl()->RegisterPictureLayerImpl(this); |
| 80 } | 82 } |
| 81 | 83 |
| 82 PictureLayerImpl::~PictureLayerImpl() { | 84 PictureLayerImpl::~PictureLayerImpl() { |
| 83 layer_tree_impl()->UnregisterPictureLayerImpl(this); | 85 layer_tree_impl()->UnregisterPictureLayerImpl(this); |
| 84 } | 86 } |
| 85 | 87 |
| 86 const char* PictureLayerImpl::LayerTypeAsString() const { | 88 const char* PictureLayerImpl::LayerTypeAsString() const { |
| 87 return "cc::PictureLayerImpl"; | 89 return "cc::PictureLayerImpl"; |
| 88 } | 90 } |
| 89 | 91 |
| 90 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( | 92 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( |
| 91 LayerTreeImpl* tree_impl) { | 93 LayerTreeImpl* tree_impl) { |
| 92 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 94 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
| 93 } | 95 } |
| 94 | 96 |
| 95 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { | 97 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { |
| 96 // It's possible this layer was never drawn or updated (e.g. because it was | 98 // It's possible this layer was never drawn or updated (e.g. because it was |
| 97 // a descendant of an opacity 0 layer). | 99 // a descendant of an opacity 0 layer). |
| 98 DoPostCommitInitializationIfNeeded(); | 100 DoPostCommitInitializationIfNeeded(); |
| 101 | |
| 99 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 102 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
| 100 | 103 |
| 101 // We have already synced the important bits from the the active layer, and | 104 // We have already synced the important bits from the the active layer, and |
| 102 // we will soon swap out its tilings and use them for recycling. However, | 105 // we will soon swap out its tilings and use them for recycling. However, |
| 103 // there are now tiles in this layer's tilings that were unref'd and replaced | 106 // there are now tiles in this layer's tilings that were unref'd and replaced |
| 104 // with new tiles (due to invalidation). This resets all active priorities on | 107 // with new tiles (due to invalidation). This resets all active priorities on |
| 105 // the to-be-recycled tiling to ensure replaced tiles don't linger and take | 108 // the to-be-recycled tiling to ensure replaced tiles don't linger and take |
| 106 // memory (due to a stale 'active' priority). | 109 // memory (due to a stale 'active' priority). |
| 107 if (layer_impl->tilings_) | 110 if (layer_impl->tilings_) |
| 108 layer_impl->tilings_->DidBecomeRecycled(); | 111 layer_impl->tilings_->DidBecomeRecycled(); |
| 109 | 112 |
| 110 LayerImpl::PushPropertiesTo(base_layer); | 113 LayerImpl::PushPropertiesTo(base_layer); |
| 111 | 114 |
| 112 // When the pending tree pushes to the active tree, the pending twin | 115 // When the pending tree pushes to the active tree, the pending twin |
| 113 // becomes recycled. | 116 // becomes recycled. |
| 114 layer_impl->twin_layer_ = NULL; | 117 layer_impl->twin_layer_ = NULL; |
| 115 twin_layer_ = NULL; | 118 twin_layer_ = NULL; |
| 116 | 119 |
| 117 layer_impl->SetIsMask(is_mask_); | 120 layer_impl->SetIsMask(is_mask_); |
| 118 layer_impl->pile_ = pile_; | 121 layer_impl->pile_ = pile_; |
| 119 | 122 |
| 123 layer_impl->is_solid_color_ = is_solid_color_; | |
| 124 layer_impl->solid_color_ = solid_color_; | |
| 125 | |
| 120 // Tilings would be expensive to push, so we swap. | 126 // Tilings would be expensive to push, so we swap. |
| 121 layer_impl->tilings_.swap(tilings_); | 127 layer_impl->tilings_.swap(tilings_); |
| 122 | 128 |
| 123 // Remove invalidated tiles from what will become a recycle tree. | 129 // Remove invalidated tiles from what will become a recycle tree. |
| 124 if (tilings_) | 130 if (tilings_) |
| 125 tilings_->RemoveTilesInRegion(invalidation_); | 131 tilings_->RemoveTilesInRegion(invalidation_); |
| 126 | 132 |
| 127 layer_impl->tilings_->SetClient(layer_impl); | 133 layer_impl->tilings_->SetClient(layer_impl); |
|
vmpstr
2014/08/29 06:49:15
If you push solid color == true, it shouldn't have
hendrikw
2014/08/29 14:03:21
We always create tilings_, but it's empty, so it s
vmpstr
2014/08/29 14:20:44
No, I guess not having tilings but having a tiling
hendrikw
2014/09/02 14:19:17
Acknowledged.
| |
| 128 if (tilings_) | 134 if (tilings_) |
| 129 tilings_->SetClient(this); | 135 tilings_->SetClient(this); |
| 130 | 136 |
| 131 layer_impl->raster_page_scale_ = raster_page_scale_; | 137 layer_impl->raster_page_scale_ = raster_page_scale_; |
| 132 layer_impl->raster_device_scale_ = raster_device_scale_; | 138 layer_impl->raster_device_scale_ = raster_device_scale_; |
| 133 layer_impl->raster_source_scale_ = raster_source_scale_; | 139 layer_impl->raster_source_scale_ = raster_source_scale_; |
| 134 layer_impl->raster_contents_scale_ = raster_contents_scale_; | 140 layer_impl->raster_contents_scale_ = raster_contents_scale_; |
| 135 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; | 141 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; |
| 136 layer_impl->needs_post_commit_initialization_ = false; | 142 layer_impl->needs_post_commit_initialization_ = false; |
| 137 | 143 |
| 138 // The invalidation on this soon-to-be-recycled layer must be cleared to | 144 // The invalidation on this soon-to-be-recycled layer must be cleared to |
| 139 // mirror clearing the invalidation in PictureLayer's version of this function | 145 // mirror clearing the invalidation in PictureLayer's version of this function |
| 140 // in case push properties is skipped. | 146 // in case push properties is skipped. |
| 141 layer_impl->invalidation_.Swap(&invalidation_); | 147 layer_impl->invalidation_.Swap(&invalidation_); |
| 142 invalidation_.Clear(); | 148 invalidation_.Clear(); |
| 143 needs_post_commit_initialization_ = true; | 149 needs_post_commit_initialization_ = true; |
| 144 | 150 |
| 145 // We always need to push properties. | 151 // We always need to push properties. |
| 146 // See http://crbug.com/303943 | 152 // See http://crbug.com/303943 |
| 147 needs_push_properties_ = true; | 153 needs_push_properties_ = true; |
| 148 } | 154 } |
| 149 | 155 |
| 150 void PictureLayerImpl::AppendQuads( | 156 void PictureLayerImpl::AppendQuads( |
| 151 RenderPass* render_pass, | 157 RenderPass* render_pass, |
| 152 const OcclusionTracker<LayerImpl>& occlusion_tracker, | 158 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
| 153 AppendQuadsData* append_quads_data) { | 159 AppendQuadsData* append_quads_data) { |
| 160 if (IsSolidColor()) { | |
|
vmpstr
2014/08/29 06:49:15
Can you put this code in a helper and do
if (IsSo
hendrikw
2014/08/29 14:03:21
As I mentioned in the post above, I will need to d
vmpstr
2014/08/29 14:20:45
Can you have a SolidColorLayerImpl as a member ins
enne (OOO)
2014/08/29 16:53:43
Please, no to either deriving from PictureLayerImp
hendrikw
2014/09/02 14:19:17
I already tried that. It calls AppendDebugBorderQ
vmpstr
2014/09/02 19:02:25
I feel that LayerImpl should really move more towa
| |
| 161 // TODO(hendrikw) code sharing | |
| 162 const int tile_size_ = 256; // this comes from solidcolorlayerimpl | |
|
vmpstr
2014/08/29 06:49:15
trailing _ is for member variables. This should be
hendrikw
2014/08/29 14:03:21
This will go away when I derive from solid color.
vmpstr
2014/08/29 14:20:44
Acknowledged.
| |
| 163 SharedQuadState* shared_quad_state = | |
| 164 render_pass->CreateAndAppendSharedQuadState(); | |
| 165 PopulateSharedQuadState(shared_quad_state); | |
| 166 | |
| 167 AppendDebugBorderQuad( | |
|
vmpstr
2014/08/29 06:49:15
Should each of the solid color quads also have a d
hendrikw
2014/08/29 14:03:21
This functionality will exist in solid color when
vmpstr
2014/08/29 14:20:44
Acknowledged.
| |
| 168 render_pass, content_bounds(), shared_quad_state, append_quads_data); | |
| 169 | |
| 170 // We create a series of smaller quads instead of just one large one so that | |
|
enne (OOO)
2014/08/29 16:53:43
This code is not your fault, but we shouldn't do t
hendrikw
2014/09/02 14:19:17
Acknowledged.
| |
| 171 // the culler can reduce the total pixels drawn. | |
| 172 int width = content_bounds().width(); | |
| 173 int height = content_bounds().height(); | |
| 174 for (int x = 0; x < width; x += tile_size_) { | |
| 175 for (int y = 0; y < height; y += tile_size_) { | |
| 176 gfx::Rect quad_rect(x, | |
| 177 y, | |
| 178 std::min(width - x, tile_size_), | |
| 179 std::min(height - y, tile_size_)); | |
| 180 gfx::Rect visible_quad_rect = occlusion_tracker.UnoccludedContentRect( | |
| 181 quad_rect, draw_properties().target_space_transform); | |
| 182 if (visible_quad_rect.IsEmpty()) | |
| 183 continue; | |
| 184 | |
| 185 SolidColorDrawQuad* quad = | |
| 186 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | |
| 187 quad->SetNew(shared_quad_state, | |
| 188 quad_rect, | |
| 189 visible_quad_rect, | |
| 190 solid_color_, | |
| 191 false); | |
| 192 } | |
| 193 } | |
| 194 return; | |
| 195 } | |
| 196 | |
| 154 DCHECK(!needs_post_commit_initialization_); | 197 DCHECK(!needs_post_commit_initialization_); |
| 155 | 198 |
| 156 float max_contents_scale = MaximumTilingContentsScale(); | 199 float max_contents_scale = MaximumTilingContentsScale(); |
| 157 gfx::Transform scaled_draw_transform = draw_transform(); | 200 gfx::Transform scaled_draw_transform = draw_transform(); |
| 158 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, | 201 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, |
| 159 SK_MScalar1 / max_contents_scale); | 202 SK_MScalar1 / max_contents_scale); |
| 160 gfx::Size scaled_content_bounds = | 203 gfx::Size scaled_content_bounds = |
| 161 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), max_contents_scale)); | 204 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), max_contents_scale)); |
| 162 | 205 |
| 163 gfx::Rect scaled_visible_content_rect = | 206 gfx::Rect scaled_visible_content_rect = |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 // to force tilings to get managed. | 620 // to force tilings to get managed. |
| 578 layer_tree_impl()->set_needs_update_draw_properties(); | 621 layer_tree_impl()->set_needs_update_draw_properties(); |
| 579 } | 622 } |
| 580 | 623 |
| 581 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { | 624 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { |
| 582 return pile_->GetFlattenedPicture(); | 625 return pile_->GetFlattenedPicture(); |
| 583 } | 626 } |
| 584 | 627 |
| 585 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, | 628 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, |
| 586 const gfx::Rect& content_rect) { | 629 const gfx::Rect& content_rect) { |
| 587 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) | 630 if (!pile_->CanRaster(tiling->contents_scale(), content_rect) || |
|
vmpstr
2014/08/29 06:49:15
Hmm, I was hoping to avoid creating tilings at all
hendrikw
2014/08/29 14:03:21
If there are no tiles in the tiling, why would upd
vmpstr
2014/08/29 14:20:45
If we don't create tilings, then this function sho
| |
| 631 IsSolidColor()) | |
| 588 return scoped_refptr<Tile>(); | 632 return scoped_refptr<Tile>(); |
| 589 | 633 |
| 590 // TODO(vmpstr): Revisit this. For now, enabling analysis means that we get as | 634 // TODO(vmpstr): Revisit this. For now, enabling analysis means that we get as |
| 591 // much savings on memory as we can. However, for some cases like ganesh or | 635 // much savings on memory as we can. However, for some cases like ganesh or |
| 592 // small layers, the amount of time we spend analyzing might not justify | 636 // small layers, the amount of time we spend analyzing might not justify |
| 593 // memory savings that we can get. | 637 // memory savings that we can get. |
| 594 // Bugs: crbug.com/397198, crbug.com/396908 | 638 // Bugs: crbug.com/397198, crbug.com/396908 |
| 595 int flags = Tile::USE_PICTURE_ANALYSIS; | 639 int flags = Tile::USE_PICTURE_ANALYSIS; |
| 596 | 640 |
| 597 return layer_tree_impl()->tile_manager()->CreateTile( | 641 return layer_tree_impl()->tile_manager()->CreateTile( |
| (...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1773 case PictureLayerTilingSet::LOWER_THAN_LOW_RES: { | 1817 case PictureLayerTilingSet::LOWER_THAN_LOW_RES: { |
| 1774 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1818 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
| 1775 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1819 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
| 1776 return tiling_range.end - 1 - current_tiling_range_offset; | 1820 return tiling_range.end - 1 - current_tiling_range_offset; |
| 1777 } | 1821 } |
| 1778 } | 1822 } |
| 1779 NOTREACHED(); | 1823 NOTREACHED(); |
| 1780 return 0; | 1824 return 0; |
| 1781 } | 1825 } |
| 1782 | 1826 |
| 1827 void PictureLayerImpl::SetSolidColorState(bool is_solid_color, | |
| 1828 SkColor solid_color) { | |
| 1829 is_solid_color_ = is_solid_color; | |
| 1830 solid_color_ = solid_color; | |
| 1831 } | |
| 1832 | |
| 1783 } // namespace cc | 1833 } // namespace cc |
| OLD | NEW |