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

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

Issue 2939243002: cc/blink: Veto checker-imaging for multipart image resources. (Closed)
Patch Set: tested 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
« no previous file with comments | « cc/paint/paint_image.cc ('k') | cc/tiles/checker_image_tracker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_multipart,
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_multipart[" << is_multipart << "]";
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 if (insert_result.second) { 175 if (insert_result.second) {
174 bool complete = 176 bool complete =
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 // The following conditions must be true for an image to be checkerable:
184 // the size constraints. 186 //
185 bool can_checker_image = complete && static_image && fits_size_constraints; 187 // 1) Complete: The data for the image should have been completely loaded.
188 //
189 // 2) Static: Animated images/video frames can not be checkered.
190 //
191 // 3) Size constraints: Small images for which the decode is expected to
192 // be fast and large images which would breach the image cache budget and
193 // go through the at-raster decode path are not checkered.
194 //
195 // 4) Multipart images: Multipart images can be used to display mjpg video
196 // frames, checkering which would cause each video frame to flash and
197 // therefore should not be checkered.
198 bool can_checker_image = complete && static_image &&
199 fits_size_constraints && !image.is_multipart();
186 if (can_checker_image) 200 if (can_checker_image)
187 it->second.policy = DecodePolicy::ASYNC; 201 it->second.policy = DecodePolicy::ASYNC;
188 202
189 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 203 TRACE_EVENT2(
190 "CheckerImageTracker::CheckerImagingDecision", 204 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
191 "can_checker_image", can_checker_image, "image_params", 205 "CheckerImageTracker::CheckerImagingDecision", "can_checker_image",
192 ToString(image_id, image.sk_image()->uniqueID(), complete, 206 can_checker_image, "image_params",
193 static_image, fits_size_constraints, size)); 207 ToString(image_id, image.sk_image()->uniqueID(), complete, static_image,
208 fits_size_constraints, image.is_multipart(), size));
194 } 209 }
195 210
196 // Update the decode state from the latest image we have seen. Note that it 211 // 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 212 // 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. 213 // each of those cases the image has already been decoded.
199 UpdateDecodeState(draw_image, image_id, &it->second); 214 UpdateDecodeState(draw_image, image_id, &it->second);
200 215
201 return it->second.policy == DecodePolicy::ASYNC; 216 return it->second.policy == DecodePolicy::ASYNC;
202 } 217 }
203 218
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 ImageController::ImageDecodeRequestId request_id = 288 ImageController::ImageDecodeRequestId request_id =
274 image_controller_->QueueImageDecode( 289 image_controller_->QueueImageDecode(
275 draw_image, base::Bind(&CheckerImageTracker::DidFinishImageDecode, 290 draw_image, base::Bind(&CheckerImageTracker::DidFinishImageDecode,
276 weak_factory_.GetWeakPtr(), image_id)); 291 weak_factory_.GetWeakPtr(), image_id));
277 292
278 image_id_to_decode_.emplace(image_id, base::MakeUnique<ScopedDecodeHolder>( 293 image_id_to_decode_.emplace(image_id, base::MakeUnique<ScopedDecodeHolder>(
279 image_controller_, request_id)); 294 image_controller_, request_id));
280 } 295 }
281 296
282 } // namespace cc 297 } // namespace cc
OLDNEW
« no previous file with comments | « cc/paint/paint_image.cc ('k') | cc/tiles/checker_image_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698