| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/managed_tile_state.h" | 5 #include "cc/resources/managed_tile_state.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 | 10 |
| 11 namespace cc { | 11 namespace cc { |
| 12 | 12 |
| 13 ManagedTileState::ManagedTileState() | 13 ManagedTileState::ManagedTileState() |
| 14 : picture_pile_analyzed(false), | 14 : picture_pile_analyzed(false), |
| 15 gpu_memmgr_stats_bin(NEVER_BIN), | 15 gpu_memmgr_stats_bin(NEVER_BIN), |
| 16 resolution(NON_IDEAL_RESOLUTION), | 16 resolution(NON_IDEAL_RESOLUTION), |
| 17 required_for_activation(false), | 17 required_for_activation(false), |
| 18 time_to_needed_in_seconds(std::numeric_limits<float>::infinity()), | 18 time_to_needed_in_seconds(std::numeric_limits<float>::infinity()), |
| 19 distance_to_visible_in_pixels(std::numeric_limits<float>::infinity()) { | 19 distance_to_visible_in_pixels(std::numeric_limits<float>::infinity()) { |
| 20 for (int i = 0; i < NUM_TREES; ++i) { | 20 for (int i = 0; i < NUM_TREES; ++i) { |
| 21 tree_bin[i] = NEVER_BIN; | 21 tree_bin[i] = NEVER_BIN; |
| 22 bin[i] = NEVER_BIN; | 22 bin[i] = NEVER_BIN; |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 ManagedTileState::TileVersion::TileVersion() | 26 ManagedTileState::TileVersion::TileVersion() |
| 27 : mode_(RESOURCE_MODE), | 27 : mode_(RESOURCE_MODE), |
| 28 resource_id_(0), | 28 resource_id_(0), |
| 29 resource_format_(GL_RGBA), | 29 resource_format_(GL_RGBA), |
| 30 forced_upload_(false) { | 30 forced_upload_(false), |
| 31 raster_mode_(INVALID_RASTER_MODE) { |
| 31 } | 32 } |
| 32 | 33 |
| 33 ManagedTileState::TileVersion::~TileVersion() { | 34 ManagedTileState::TileVersion::~TileVersion() { |
| 34 DCHECK(!resource_); | 35 DCHECK(!resource_); |
| 35 } | 36 } |
| 36 | 37 |
| 37 bool ManagedTileState::TileVersion::IsReadyToDraw() const { | 38 bool ManagedTileState::TileVersion::IsReadyToDraw() const { |
| 38 switch (mode_) { | 39 switch (mode_) { |
| 39 case RESOURCE_MODE: | 40 case RESOURCE_MODE: |
| 40 return resource_id_ && (resource_ || forced_upload_); | 41 return resource_id_ && (resource_ || forced_upload_); |
| 41 case SOLID_COLOR_MODE: | 42 case SOLID_COLOR_MODE: |
| 42 case PICTURE_PILE_MODE: | 43 case PICTURE_PILE_MODE: |
| 43 return true; | 44 return true; |
| 44 default: | 45 default: |
| 45 NOTREACHED(); | 46 NOTREACHED(); |
| 46 return false; | 47 return false; |
| 47 } | 48 } |
| 48 } | 49 } |
| 49 | 50 |
| 50 size_t ManagedTileState::TileVersion::GPUMemoryUsageInBytes() const { | 51 size_t ManagedTileState::TileVersion::GPUMemoryUsageInBytes() const { |
| 51 if (!resource_) | 52 if (!resource_) |
| 52 return 0; | 53 return 0; |
| 53 return resource_->bytes(); | 54 return resource_->bytes(); |
| 54 } | 55 } |
| 55 | 56 |
| 57 bool ManagedTileState::TileVersion::ShouldBeUpdatedBy( |
| 58 TileRasterMode new_mode) const { |
| 59 return new_mode > raster_mode_; |
| 60 } |
| 61 |
| 62 void ManagedTileState::TileVersion::PushPropertiesTo(TileVersion* destination) { |
| 63 destination->mode_ = mode_; |
| 64 destination->solid_color_ = solid_color_; |
| 65 destination->resource_id_ = resource_ ? resource_->id() : resource_id_; |
| 66 destination->resource_ = resource_.Pass(); |
| 67 destination->resource_format_ = resource_format_; |
| 68 destination->forced_upload_ = forced_upload_; |
| 69 destination->raster_mode_ = raster_mode_; |
| 70 destination->raster_task_ = raster_task_; |
| 71 } |
| 72 |
| 56 ManagedTileState::~ManagedTileState() { | 73 ManagedTileState::~ManagedTileState() { |
| 57 } | 74 } |
| 58 | 75 |
| 59 scoped_ptr<base::Value> ManagedTileState::AsValue() const { | 76 scoped_ptr<base::Value> ManagedTileState::AsValue() const { |
| 60 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 77 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 61 state->SetBoolean("has_resource", tile_version.resource_.get() != 0); | 78 state->SetBoolean("has_resource", tile_version.resource_.get() != 0); |
| 62 state->Set("bin.0", TileManagerBinAsValue(bin[ACTIVE_TREE]).release()); | 79 state->Set("bin.0", TileManagerBinAsValue(bin[ACTIVE_TREE]).release()); |
| 63 state->Set("bin.1", TileManagerBinAsValue(bin[PENDING_TREE]).release()); | 80 state->Set("bin.1", TileManagerBinAsValue(bin[PENDING_TREE]).release()); |
| 64 state->Set("gpu_memmgr_stats_bin", | 81 state->Set("gpu_memmgr_stats_bin", |
| 65 TileManagerBinAsValue(bin[ACTIVE_TREE]).release()); | 82 TileManagerBinAsValue(bin[ACTIVE_TREE]).release()); |
| 66 state->Set("resolution", TileResolutionAsValue(resolution).release()); | 83 state->Set("resolution", TileResolutionAsValue(resolution).release()); |
| 67 state->Set("time_to_needed_in_seconds", | 84 state->Set("time_to_needed_in_seconds", |
| 68 MathUtil::AsValueSafely(time_to_needed_in_seconds).release()); | 85 MathUtil::AsValueSafely(time_to_needed_in_seconds).release()); |
| 69 state->Set("distance_to_visible_in_pixels", | 86 state->Set("distance_to_visible_in_pixels", |
| 70 MathUtil::AsValueSafely(distance_to_visible_in_pixels).release()); | 87 MathUtil::AsValueSafely(distance_to_visible_in_pixels).release()); |
| 71 state->SetBoolean("required_for_activation", required_for_activation); | 88 state->SetBoolean("required_for_activation", required_for_activation); |
| 72 state->SetBoolean("is_picture_pile_analyzed", picture_pile_analyzed); | 89 state->SetBoolean("is_picture_pile_analyzed", picture_pile_analyzed); |
| 73 state->SetBoolean("is_solid_color", picture_pile_analysis.is_solid_color); | 90 state->SetBoolean("is_solid_color", picture_pile_analysis.is_solid_color); |
| 74 state->SetBoolean("is_transparent", | 91 state->SetBoolean("is_transparent", |
| 75 picture_pile_analysis.is_solid_color && | 92 picture_pile_analysis.is_solid_color && |
| 76 !SkColorGetA(picture_pile_analysis.solid_color)); | 93 !SkColorGetA(picture_pile_analysis.solid_color)); |
| 77 return state.PassAs<base::Value>(); | 94 return state.PassAs<base::Value>(); |
| 78 } | 95 } |
| 79 | 96 |
| 80 } // namespace cc | 97 } // namespace cc |
| 81 | 98 |
| OLD | NEW |