Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1644)

Unified Diff: cc/tiles/checker_image_tracker.cc

Issue 2928433003: cc: Add scaling for checkered images. (Closed)
Patch Set: comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/tiles/checker_image_tracker.cc
diff --git a/cc/tiles/checker_image_tracker.cc b/cc/tiles/checker_image_tracker.cc
index 022269d87a95fa52d4661581e4c527c4799f32d4..35998773b3ee9bab9a03261d60fc067f3e6dd501 100644
--- a/cc/tiles/checker_image_tracker.cc
+++ b/cc/tiles/checker_image_tracker.cc
@@ -21,8 +21,24 @@ size_t SafeSizeOfImage(const SkImage* image) {
return checked_size.ValueOrDefault(std::numeric_limits<size_t>::max());
}
+std::string ToString(PaintImage::Id paint_image_id,
+ SkImageId sk_image_id,
+ bool complete,
+ bool static_image,
+ bool fits_size_constraints,
+ size_t size) {
+ std::ostringstream str;
+ str << "paint_image_id[" << paint_image_id << "] sk_image_id[" << sk_image_id
+ << "] complete[" << complete << "] static[" << static_image
+ << "], fits_size_constraints[" << fits_size_constraints << "], size["
+ << size << "]";
+ return str.str();
+}
+
} // namespace
+CheckerImageTracker::DecodeState::DecodeState() : scale(SkSize::MakeEmpty()) {}
+
CheckerImageTracker::CheckerImageTracker(ImageController* image_controller,
CheckerImageTrackerClient* client,
bool enable_checker_imaging)
@@ -90,9 +106,9 @@ void CheckerImageTracker::ClearTracker(bool can_clear_decode_policy_tracking) {
auto it = image_async_decode_state_.find(image_id);
DCHECK(it != image_async_decode_state_.end());
- DCHECK_EQ(it->second, DecodePolicy::SYNC_DECODED_ONCE);
+ DCHECK_EQ(it->second.policy, DecodePolicy::SYNC_DECODED_ONCE);
- it->second = DecodePolicy::ASYNC;
+ it->second.policy = DecodePolicy::ASYNC;
}
}
images_pending_invalidation_.clear();
@@ -119,22 +135,22 @@ void CheckerImageTracker::DidFinishImageDecode(
return;
}
- it->second = DecodePolicy::SYNC_DECODED_ONCE;
+ it->second.policy = DecodePolicy::SYNC_DECODED_ONCE;
images_pending_invalidation_.insert(image_id);
ScheduleNextImageDecode();
client_->NeedsInvalidationForCheckerImagedTiles();
}
-bool CheckerImageTracker::ShouldCheckerImage(const PaintImage& image,
+bool CheckerImageTracker::ShouldCheckerImage(const DrawImage& draw_image,
WhichTree tree) {
+ const PaintImage& image = draw_image.paint_image();
+ PaintImage::Id image_id = image.stable_id();
TRACE_EVENT1("cc", "CheckerImageTracker::ShouldCheckerImage", "image_id",
- image.stable_id());
+ image_id);
if (!enable_checker_imaging_)
return false;
- PaintImage::Id image_id = image.stable_id();
-
// If the image was invalidated on the current sync tree and the tile is
// for the active tree, continue checkering it on the active tree to ensure
// the image update is atomic for the frame.
@@ -150,24 +166,64 @@ bool CheckerImageTracker::ShouldCheckerImage(const PaintImage& image,
return true;
}
- auto insert_result =
- image_async_decode_state_.insert(std::pair<PaintImage::Id, DecodePolicy>(
- image_id, DecodePolicy::SYNC_PERMANENT));
+ auto insert_result = image_async_decode_state_.insert(
+ std::pair<PaintImage::Id, DecodeState>(image_id, DecodeState()));
auto it = insert_result.first;
if (insert_result.second) {
- bool can_checker_image =
- image.animation_type() == PaintImage::AnimationType::STATIC &&
+ bool complete =
image.completion_state() == PaintImage::CompletionState::DONE;
- if (can_checker_image) {
- size_t size = SafeSizeOfImage(image.sk_image().get());
- it->second = (size >= kMinImageSizeToCheckerBytes &&
- size <= image_controller_->image_cache_max_limit_bytes())
- ? DecodePolicy::ASYNC
- : DecodePolicy::SYNC_PERMANENT;
- }
+ bool static_image =
+ image.animation_type() == PaintImage::AnimationType::STATIC;
+
+ size_t size = SafeSizeOfImage(image.sk_image().get());
+ bool fits_size_constraints =
+ size >= kMinImageSizeToCheckerBytes &&
+ size <= image_controller_->image_cache_max_limit_bytes();
+
+ // Only checker images that are static and completely loaded and fit within
+ // the size constraints.
+ bool can_checker_image = complete && static_image && fits_size_constraints;
+ if (can_checker_image)
+ it->second.policy = DecodePolicy::ASYNC;
+ TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
+ "CheckerImageTracker::CheckerImagingDecision",
+ "can_checker_image", can_checker_image, "image_params",
+ ToString(image_id, image.stable_id(), complete, static_image,
+ fits_size_constraints, size));
+ }
+
+ // Update the decode state from the latest image we have seen. Note that it
+ // is not necessary to perform this in the early out cases above since in
+ // each of those cases the image has already been decoded.
+ UpdateDecodeState(draw_image, image_id, &it->second);
+
+ return it->second.policy == DecodePolicy::ASYNC;
+}
+
+void CheckerImageTracker::UpdateDecodeState(const DrawImage& draw_image,
+ PaintImage::Id paint_image_id,
+ DecodeState* decode_state) {
+ // If the policy is not async then either we decoded this image already or
+ // we decided not to ever checker it.
+ if (decode_state->policy != DecodePolicy::ASYNC)
+ return;
+
+ // If the decode is already in flight, then we will have to live with what we
+ // have now.
+ if (outstanding_image_decode_.has_value() &&
+ outstanding_image_decode_.value().stable_id() == paint_image_id) {
+ return;
}
- return it->second == DecodePolicy::ASYNC;
+ // Choose the max scale and filter quality. This keeps the memory usage to the
+ // minimum possible while still increasing the possibility of getting a cache
+ // hit.
+ decode_state->scale = SkSize::Make(
+ std::max(decode_state->scale.fWidth, draw_image.scale().fWidth),
+ std::max(decode_state->scale.fHeight, draw_image.scale().fHeight));
+ decode_state->filter_quality =
+ std::max(decode_state->filter_quality, draw_image.filter_quality());
+ decode_state->color_space = draw_image.target_color_space();
}
void CheckerImageTracker::ScheduleNextImageDecode() {
@@ -178,6 +234,7 @@ void CheckerImageTracker::ScheduleNextImageDecode() {
if (outstanding_image_decode_.has_value())
return;
+ DrawImage draw_image;
while (!image_decode_queue_.empty()) {
auto candidate = std::move(image_decode_queue_.front());
image_decode_queue_.erase(image_decode_queue_.begin());
@@ -189,9 +246,14 @@ void CheckerImageTracker::ScheduleNextImageDecode() {
PaintImage::Id image_id = candidate.stable_id();
auto it = image_async_decode_state_.find(image_id);
DCHECK(it != image_async_decode_state_.end());
- if (it->second != DecodePolicy::ASYNC)
+ if (it->second.policy != DecodePolicy::ASYNC)
continue;
+ draw_image = DrawImage(candidate, candidate.sk_image()->bounds(),
+ it->second.filter_quality,
+ SkMatrix::MakeScale(it->second.scale.width(),
+ it->second.scale.height()),
+ it->second.color_space);
outstanding_image_decode_.emplace(candidate);
break;
}
@@ -209,9 +271,8 @@ void CheckerImageTracker::ScheduleNextImageDecode() {
image_id);
ImageController::ImageDecodeRequestId request_id =
image_controller_->QueueImageDecode(
- outstanding_image_decode_.value().sk_image(),
- base::Bind(&CheckerImageTracker::DidFinishImageDecode,
- weak_factory_.GetWeakPtr(), image_id));
+ draw_image, base::Bind(&CheckerImageTracker::DidFinishImageDecode,
+ weak_factory_.GetWeakPtr(), image_id));
image_id_to_decode_.emplace(image_id, base::MakeUnique<ScopedDecodeHolder>(
image_controller_, request_id));

Powered by Google App Engine
This is Rietveld 408576698