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

Side by Side Diff: cc/tiles/checker_image_tracker.cc

Issue 2939243002: cc/blink: Veto checker-imaging for multipart image resources. (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/tiles/checker_image_tracker.h" 5 #include "cc/tiles/checker_image_tracker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
11 11
12 namespace cc { 12 namespace cc {
13 namespace { 13 namespace {
14 // The minimum size of an image that we should consider checkering. 14 // The minimum size of an image that we should consider checkering.
15 size_t kMinImageSizeToCheckerBytes = 512 * 1024; 15 size_t kMinImageSizeToCheckerBytes = 512 * 1024;
16 16
17 size_t SafeSizeOfImage(const SkImage* image) { 17 size_t SafeSizeOfImage(const SkImage* image) {
18 base::CheckedNumeric<size_t> checked_size = 4; 18 base::CheckedNumeric<size_t> checked_size = 4;
19 checked_size *= image->width(); 19 checked_size *= image->width();
20 checked_size *= image->height(); 20 checked_size *= image->height();
21 return checked_size.ValueOrDefault(std::numeric_limits<size_t>::max()); 21 return checked_size.ValueOrDefault(std::numeric_limits<size_t>::max());
22 } 22 }
23 23
24 std::string ToString(PaintImage::Id paint_image_id, 24 std::string ToString(PaintImage::Id paint_image_id,
25 SkImageId sk_image_id, 25 SkImageId sk_image_id,
26 bool complete, 26 bool complete,
27 bool static_image, 27 bool static_image,
28 bool fits_size_constraints, 28 bool fits_size_constraints,
29 bool is_multi_part,
29 size_t size) { 30 size_t size) {
30 std::ostringstream str; 31 std::ostringstream str;
31 str << "paint_image_id[" << paint_image_id << "] sk_image_id[" << sk_image_id 32 str << "paint_image_id[" << paint_image_id << "] sk_image_id[" << sk_image_id
32 << "] complete[" << complete << "] static[" << static_image 33 << "] complete[" << complete << "] static[" << static_image
33 << "], fits_size_constraints[" << fits_size_constraints << "], size[" 34 << "], fits_size_constraints[" << fits_size_constraints << "], size["
34 << size << "]"; 35 << size << "]"
36 << " is_multi_part[" << is_multi_part << "]";
35 return str.str(); 37 return str.str();
36 } 38 }
37 39
38 } // namespace 40 } // namespace
39 41
40 CheckerImageTracker::CheckerImageTracker(ImageController* image_controller, 42 CheckerImageTracker::CheckerImageTracker(ImageController* image_controller,
41 CheckerImageTrackerClient* client, 43 CheckerImageTrackerClient* client,
42 bool enable_checker_imaging) 44 bool enable_checker_imaging)
43 : image_controller_(image_controller), 45 : image_controller_(image_controller),
44 client_(client), 46 client_(client),
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 image.completion_state() == PaintImage::CompletionState::DONE; 177 image.completion_state() == PaintImage::CompletionState::DONE;
176 bool static_image = 178 bool static_image =
177 image.animation_type() == PaintImage::AnimationType::STATIC; 179 image.animation_type() == PaintImage::AnimationType::STATIC;
178 size_t size = SafeSizeOfImage(image.sk_image().get()); 180 size_t size = SafeSizeOfImage(image.sk_image().get());
179 bool fits_size_constraints = 181 bool fits_size_constraints =
180 size >= kMinImageSizeToCheckerBytes && 182 size >= kMinImageSizeToCheckerBytes &&
181 size <= image_controller_->image_cache_max_limit_bytes(); 183 size <= image_controller_->image_cache_max_limit_bytes();
182 184
183 // Only checker images that are static and completely loaded and fit within 185 // Only checker images that are static and completely loaded and fit within
184 // the size constraints. 186 // the size constraints.
185 bool can_checker_image = complete && static_image && fits_size_constraints; 187 bool can_checker_image = complete && static_image &&
vmpstr 2017/06/16 17:35:36 Can you update the comment to state in words when
188 fits_size_constraints && !image.is_multi_part();
186 if (can_checker_image) 189 if (can_checker_image)
187 it->second.policy = DecodePolicy::ASYNC; 190 it->second.policy = DecodePolicy::ASYNC;
188 191
189 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 192 TRACE_EVENT2(
190 "CheckerImageTracker::CheckerImagingDecision", 193 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
191 "can_checker_image", can_checker_image, "image_params", 194 "CheckerImageTracker::CheckerImagingDecision", "can_checker_image",
192 ToString(image_id, image.sk_image()->uniqueID(), complete, 195 can_checker_image, "image_params",
193 static_image, fits_size_constraints, size)); 196 ToString(image_id, image.sk_image()->uniqueID(), complete, static_image,
197 fits_size_constraints, image.is_multi_part(), size));
194 } 198 }
195 199
196 // Update the decode state from the latest image we have seen. Note that it 200 // Update the decode state from the latest image we have seen. Note that it
197 // is not necessary to perform this in the early out cases above since in 201 // is not necessary to perform this in the early out cases above since in
198 // each of those cases the image has already been decoded. 202 // each of those cases the image has already been decoded.
199 UpdateDecodeState(draw_image, image_id, &it->second); 203 UpdateDecodeState(draw_image, image_id, &it->second);
200 204
201 return it->second.policy == DecodePolicy::ASYNC; 205 return it->second.policy == DecodePolicy::ASYNC;
202 } 206 }
203 207
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 ImageController::ImageDecodeRequestId request_id = 277 ImageController::ImageDecodeRequestId request_id =
274 image_controller_->QueueImageDecode( 278 image_controller_->QueueImageDecode(
275 draw_image, base::Bind(&CheckerImageTracker::DidFinishImageDecode, 279 draw_image, base::Bind(&CheckerImageTracker::DidFinishImageDecode,
276 weak_factory_.GetWeakPtr(), image_id)); 280 weak_factory_.GetWeakPtr(), image_id));
277 281
278 image_id_to_decode_.emplace(image_id, base::MakeUnique<ScopedDecodeHolder>( 282 image_id_to_decode_.emplace(image_id, base::MakeUnique<ScopedDecodeHolder>(
279 image_controller_, request_id)); 283 image_controller_, request_id));
280 } 284 }
281 285
282 } // namespace cc 286 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698