OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/raster/raster_source.h" | 5 #include "cc/raster/raster_source.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 recorded_viewport_(other->recorded_viewport_), | 54 recorded_viewport_(other->recorded_viewport_), |
55 size_(other->size_), | 55 size_(other->size_), |
56 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), | 56 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), |
57 slow_down_raster_scale_factor_for_debug_( | 57 slow_down_raster_scale_factor_for_debug_( |
58 other->slow_down_raster_scale_factor_for_debug_), | 58 other->slow_down_raster_scale_factor_for_debug_), |
59 image_decode_cache_(other->image_decode_cache_) {} | 59 image_decode_cache_(other->image_decode_cache_) {} |
60 | 60 |
61 RasterSource::~RasterSource() {} | 61 RasterSource::~RasterSource() {} |
62 | 62 |
63 void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas, | 63 void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas, |
64 const gfx::ColorSpace& canvas_color_space, | 64 const gfx::ColorSpace& target_color_space, |
65 const gfx::Rect& canvas_bitmap_rect, | 65 const gfx::Rect& canvas_bitmap_rect, |
66 const gfx::Rect& canvas_playback_rect, | 66 const gfx::Rect& canvas_playback_rect, |
67 float raster_scale, | 67 float raster_scale, |
68 const PlaybackSettings& settings) const { | 68 const PlaybackSettings& settings) const { |
69 SkIRect raster_bounds = gfx::RectToSkIRect(canvas_bitmap_rect); | 69 SkIRect raster_bounds = gfx::RectToSkIRect(canvas_bitmap_rect); |
70 if (!canvas_playback_rect.IsEmpty() && | 70 if (!canvas_playback_rect.IsEmpty() && |
71 !raster_bounds.intersect(gfx::RectToSkIRect(canvas_playback_rect))) | 71 !raster_bounds.intersect(gfx::RectToSkIRect(canvas_playback_rect))) |
72 return; | 72 return; |
73 // Treat all subnormal values as zero for performance. | 73 // Treat all subnormal values as zero for performance. |
74 ScopedSubnormalFloatDisabler disabler; | 74 ScopedSubnormalFloatDisabler disabler; |
75 | 75 |
76 raster_canvas->save(); | 76 raster_canvas->save(); |
77 raster_canvas->translate(-canvas_bitmap_rect.x(), -canvas_bitmap_rect.y()); | 77 raster_canvas->translate(-canvas_bitmap_rect.x(), -canvas_bitmap_rect.y()); |
78 raster_canvas->clipRect(SkRect::MakeFromIRect(raster_bounds)); | 78 raster_canvas->clipRect(SkRect::MakeFromIRect(raster_bounds)); |
79 raster_canvas->scale(raster_scale, raster_scale); | 79 raster_canvas->scale(raster_scale, raster_scale); |
80 PlaybackToCanvas(raster_canvas, canvas_color_space, settings); | 80 PlaybackToCanvas(raster_canvas, target_color_space, settings); |
81 raster_canvas->restore(); | 81 raster_canvas->restore(); |
82 } | 82 } |
83 | 83 |
84 void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas, | 84 void RasterSource::PlaybackToCanvas(SkCanvas* input_canvas, |
85 const gfx::ColorSpace& canvas_color_space, | 85 const gfx::ColorSpace& target_color_space, |
86 const PlaybackSettings& settings) const { | 86 const PlaybackSettings& settings) const { |
87 SkCanvas* raster_canvas = input_canvas; | |
88 std::unique_ptr<SkCanvas> color_transform_canvas; | |
89 if (target_color_space.IsValid()) { | |
90 color_transform_canvas = SkCreateColorSpaceXformCanvas( | |
91 input_canvas, target_color_space.ToSkColorSpace()); | |
92 raster_canvas = color_transform_canvas.get(); | |
93 } | |
94 | |
87 if (!settings.playback_to_shared_canvas) | 95 if (!settings.playback_to_shared_canvas) |
88 PrepareForPlaybackToCanvas(raster_canvas); | 96 PrepareForPlaybackToCanvas(raster_canvas); |
89 | 97 |
90 if (settings.skip_images) { | 98 if (settings.skip_images) { |
91 SkipImageCanvas canvas(raster_canvas); | 99 SkipImageCanvas canvas(raster_canvas); |
92 RasterCommon(&canvas, canvas_color_space, nullptr); | 100 RasterCommon(&canvas, nullptr); |
93 } else if (settings.use_image_hijack_canvas) { | 101 } else if (settings.use_image_hijack_canvas) { |
94 const SkImageInfo& info = raster_canvas->imageInfo(); | 102 const SkImageInfo& info = raster_canvas->imageInfo(); |
95 ImageHijackCanvas canvas(info.width(), info.height(), image_decode_cache_, | 103 ImageHijackCanvas canvas(info.width(), info.height(), image_decode_cache_, |
96 &settings.images_to_skip); | 104 &settings.images_to_skip, target_color_space); |
vmpstr
2017/04/04 01:16:43
ImageHijackCanvas intercepts some calls to things
ccameron
2017/04/04 06:41:10
Yeah, the input SkImage will be in "image color sp
| |
97 // Before adding the canvas, make sure that the ImageHijackCanvas is aware | 105 // Before adding the canvas, make sure that the ImageHijackCanvas is aware |
98 // of the current transform and clip, which may affect the clip bounds. | 106 // of the current transform and clip, which may affect the clip bounds. |
99 // Since we query the clip bounds of the current canvas to get the list of | 107 // Since we query the clip bounds of the current canvas to get the list of |
100 // draw commands to process, this is important to produce correct content. | 108 // draw commands to process, this is important to produce correct content. |
101 canvas.clipRect( | 109 canvas.clipRect( |
102 SkRect::MakeFromIRect(raster_canvas->getDeviceClipBounds())); | 110 SkRect::MakeFromIRect(raster_canvas->getDeviceClipBounds())); |
103 canvas.setMatrix(raster_canvas->getTotalMatrix()); | 111 canvas.setMatrix(raster_canvas->getTotalMatrix()); |
104 canvas.addCanvas(raster_canvas); | 112 canvas.addCanvas(raster_canvas); |
105 | 113 |
106 RasterCommon(&canvas, canvas_color_space, nullptr); | 114 RasterCommon(&canvas, nullptr); |
107 } else { | 115 } else { |
108 RasterCommon(raster_canvas, canvas_color_space, nullptr); | 116 RasterCommon(raster_canvas, nullptr); |
109 } | 117 } |
110 } | 118 } |
111 | 119 |
112 namespace { | 120 namespace { |
113 | 121 |
114 bool CanvasIsUnclipped(const SkCanvas* canvas) { | 122 bool CanvasIsUnclipped(const SkCanvas* canvas) { |
115 if (!canvas->isClipRect()) | 123 if (!canvas->isClipRect()) |
116 return false; | 124 return false; |
117 | 125 |
118 SkIRect bounds; | 126 SkIRect bounds; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 canvas->save(); | 199 canvas->save(); |
192 // Use clipRegion to bypass CTM because the rects are device rects. | 200 // Use clipRegion to bypass CTM because the rects are device rects. |
193 SkRegion interest_region; | 201 SkRegion interest_region; |
194 interest_region.setRect(interest_rect); | 202 interest_region.setRect(interest_rect); |
195 interest_region.op(opaque_rect, SkRegion::kDifference_Op); | 203 interest_region.op(opaque_rect, SkRegion::kDifference_Op); |
196 canvas->clipRegion(interest_region); | 204 canvas->clipRegion(interest_region); |
197 canvas->clear(background_color_); | 205 canvas->clear(background_color_); |
198 canvas->restore(); | 206 canvas->restore(); |
199 } | 207 } |
200 | 208 |
201 void RasterSource::RasterCommon(SkCanvas* input_canvas, | 209 void RasterSource::RasterCommon(SkCanvas* raster_canvas, |
202 const gfx::ColorSpace& target_color_space, | |
203 SkPicture::AbortCallback* callback) const { | 210 SkPicture::AbortCallback* callback) const { |
204 SkCanvas* raster_canvas = input_canvas; | |
205 std::unique_ptr<SkCanvas> color_transform_canvas; | |
206 if (target_color_space.IsValid()) { | |
207 color_transform_canvas = SkCreateColorSpaceXformCanvas( | |
208 input_canvas, target_color_space.ToSkColorSpace()); | |
209 raster_canvas = color_transform_canvas.get(); | |
210 } | |
211 DCHECK(display_list_.get()); | 211 DCHECK(display_list_.get()); |
212 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); | 212 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); |
213 for (int i = 0; i < repeat_count; ++i) | 213 for (int i = 0; i < repeat_count; ++i) |
214 display_list_->Raster(raster_canvas, callback); | 214 display_list_->Raster(raster_canvas, callback); |
215 } | 215 } |
216 | 216 |
217 sk_sp<SkPicture> RasterSource::GetFlattenedPicture() { | 217 sk_sp<SkPicture> RasterSource::GetFlattenedPicture() { |
218 TRACE_EVENT0("cc", "RasterSource::GetFlattenedPicture"); | 218 TRACE_EVENT0("cc", "RasterSource::GetFlattenedPicture"); |
219 | 219 |
220 SkPictureRecorder recorder; | 220 SkPictureRecorder recorder; |
221 SkCanvas* canvas = recorder.beginRecording(size_.width(), size_.height()); | 221 SkCanvas* canvas = recorder.beginRecording(size_.width(), size_.height()); |
222 if (!size_.IsEmpty()) { | 222 if (!size_.IsEmpty()) { |
223 PrepareForPlaybackToCanvas(canvas); | 223 PrepareForPlaybackToCanvas(canvas); |
224 // No target color space should be set for generating an SkPicture. | 224 RasterCommon(canvas, nullptr); |
225 RasterCommon(canvas, gfx::ColorSpace(), nullptr); | |
226 } | 225 } |
227 | 226 |
228 return recorder.finishRecordingAsPicture(); | 227 return recorder.finishRecordingAsPicture(); |
229 } | 228 } |
230 | 229 |
231 size_t RasterSource::GetMemoryUsage() const { | 230 size_t RasterSource::GetMemoryUsage() const { |
232 if (!display_list_) | 231 if (!display_list_) |
233 return 0; | 232 return 0; |
234 return display_list_->ApproximateMemoryUsage() + | 233 return display_list_->ApproximateMemoryUsage() + |
235 painter_reported_memory_usage_; | 234 painter_reported_memory_usage_; |
236 } | 235 } |
237 | 236 |
238 bool RasterSource::PerformSolidColorAnalysis(const gfx::Rect& content_rect, | 237 bool RasterSource::PerformSolidColorAnalysis(const gfx::Rect& content_rect, |
239 float contents_scale, | 238 float contents_scale, |
240 SkColor* color) const { | 239 SkColor* color) const { |
241 TRACE_EVENT0("cc", "RasterSource::PerformSolidColorAnalysis"); | 240 TRACE_EVENT0("cc", "RasterSource::PerformSolidColorAnalysis"); |
242 | 241 |
243 gfx::Rect layer_rect = | 242 gfx::Rect layer_rect = |
244 gfx::ScaleToEnclosingRect(content_rect, 1.f / contents_scale); | 243 gfx::ScaleToEnclosingRect(content_rect, 1.f / contents_scale); |
245 | 244 |
246 layer_rect.Intersect(gfx::Rect(size_)); | 245 layer_rect.Intersect(gfx::Rect(size_)); |
247 skia::AnalysisCanvas canvas(layer_rect.width(), layer_rect.height()); | 246 skia::AnalysisCanvas canvas(layer_rect.width(), layer_rect.height()); |
248 canvas.translate(-layer_rect.x(), -layer_rect.y()); | 247 canvas.translate(-layer_rect.x(), -layer_rect.y()); |
249 // No target color space should be set for solid color analysis (the | 248 // Note that because no color conversion is applied to solid color analysis, |
250 // resulting solid color will be known to be sRGB). | 249 // the resulting solid color will be known to be sRGB. |
251 RasterCommon(&canvas, gfx::ColorSpace(), &canvas); | 250 RasterCommon(&canvas, &canvas); |
252 return canvas.GetColorIfSolid(color); | 251 return canvas.GetColorIfSolid(color); |
253 } | 252 } |
254 | 253 |
255 void RasterSource::GetDiscardableImagesInRect( | 254 void RasterSource::GetDiscardableImagesInRect( |
256 const gfx::Rect& layer_rect, | 255 const gfx::Rect& layer_rect, |
257 float contents_scale, | 256 float contents_scale, |
257 const gfx::ColorSpace& target_color_space, | |
258 std::vector<DrawImage>* images) const { | 258 std::vector<DrawImage>* images) const { |
259 DCHECK_EQ(0u, images->size()); | 259 DCHECK_EQ(0u, images->size()); |
260 display_list_->GetDiscardableImagesInRect(layer_rect, contents_scale, images); | 260 display_list_->GetDiscardableImagesInRect(layer_rect, contents_scale, |
261 target_color_space, images); | |
261 } | 262 } |
262 | 263 |
263 gfx::Rect RasterSource::GetRectForImage(ImageId image_id) const { | 264 gfx::Rect RasterSource::GetRectForImage(ImageId image_id) const { |
264 if (!display_list_) | 265 if (!display_list_) |
265 return gfx::Rect(); | 266 return gfx::Rect(); |
266 return display_list_->GetRectForImage(image_id); | 267 return display_list_->GetRectForImage(image_id); |
267 } | 268 } |
268 | 269 |
269 bool RasterSource::CoversRect(const gfx::Rect& layer_rect) const { | 270 bool RasterSource::CoversRect(const gfx::Rect& layer_rect) const { |
270 if (size_.IsEmpty()) | 271 if (size_.IsEmpty()) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 use_image_hijack_canvas(true) {} | 321 use_image_hijack_canvas(true) {} |
321 | 322 |
322 RasterSource::PlaybackSettings::PlaybackSettings(const PlaybackSettings&) = | 323 RasterSource::PlaybackSettings::PlaybackSettings(const PlaybackSettings&) = |
323 default; | 324 default; |
324 | 325 |
325 RasterSource::PlaybackSettings::PlaybackSettings(PlaybackSettings&&) = default; | 326 RasterSource::PlaybackSettings::PlaybackSettings(PlaybackSettings&&) = default; |
326 | 327 |
327 RasterSource::PlaybackSettings::~PlaybackSettings() = default; | 328 RasterSource::PlaybackSettings::~PlaybackSettings() = default; |
328 | 329 |
329 } // namespace cc | 330 } // namespace cc |
OLD | NEW |