Chromium Code Reviews| 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/playback/raster_source.h" | 5 #include "cc/playback/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" |
| 11 #include "cc/base/region.h" | 11 #include "cc/base/region.h" |
| 12 #include "cc/debug/debug_colors.h" | 12 #include "cc/debug/debug_colors.h" |
| 13 #include "cc/paint/paint_recorder.h" | |
| 13 #include "cc/playback/display_item_list.h" | 14 #include "cc/playback/display_item_list.h" |
| 14 #include "cc/playback/image_hijack_canvas.h" | 15 #include "cc/playback/image_hijack_canvas.h" |
| 15 #include "cc/playback/skip_image_canvas.h" | 16 #include "cc/playback/skip_image_canvas.h" |
| 16 #include "skia/ext/analysis_canvas.h" | 17 #include "skia/ext/analysis_canvas.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | |
| 18 #include "third_party/skia/include/core/SkClipStack.h" | 18 #include "third_party/skia/include/core/SkClipStack.h" |
|
danakj
2017/01/20 23:34:13
is used?
| |
| 19 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
| 20 #include "ui/gfx/geometry/rect_conversions.h" | 19 #include "ui/gfx/geometry/rect_conversions.h" |
| 21 | 20 |
| 22 namespace cc { | 21 namespace cc { |
| 23 | 22 |
| 24 scoped_refptr<RasterSource> RasterSource::CreateFromRecordingSource( | 23 scoped_refptr<RasterSource> RasterSource::CreateFromRecordingSource( |
| 25 const RecordingSource* other, | 24 const RecordingSource* other, |
| 26 bool can_use_lcd_text) { | 25 bool can_use_lcd_text) { |
| 27 return make_scoped_refptr(new RasterSource(other, can_use_lcd_text)); | 26 return make_scoped_refptr(new RasterSource(other, can_use_lcd_text)); |
| 28 } | 27 } |
| 29 | 28 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 53 recorded_viewport_(other->recorded_viewport_), | 52 recorded_viewport_(other->recorded_viewport_), |
| 54 size_(other->size_), | 53 size_(other->size_), |
| 55 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), | 54 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), |
| 56 slow_down_raster_scale_factor_for_debug_( | 55 slow_down_raster_scale_factor_for_debug_( |
| 57 other->slow_down_raster_scale_factor_for_debug_), | 56 other->slow_down_raster_scale_factor_for_debug_), |
| 58 image_decode_cache_(other->image_decode_cache_) {} | 57 image_decode_cache_(other->image_decode_cache_) {} |
| 59 | 58 |
| 60 RasterSource::~RasterSource() { | 59 RasterSource::~RasterSource() { |
| 61 } | 60 } |
| 62 | 61 |
| 63 void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas, | 62 void RasterSource::PlaybackToCanvas(PaintCanvas* raster_canvas, |
| 64 const gfx::Rect& canvas_bitmap_rect, | 63 const gfx::Rect& canvas_bitmap_rect, |
| 65 const gfx::Rect& canvas_playback_rect, | 64 const gfx::Rect& canvas_playback_rect, |
| 66 float raster_scale, | 65 float raster_scale, |
| 67 const PlaybackSettings& settings) const { | 66 const PlaybackSettings& settings) const { |
| 68 SkIRect raster_bounds = gfx::RectToSkIRect(canvas_bitmap_rect); | 67 SkIRect raster_bounds = gfx::RectToSkIRect(canvas_bitmap_rect); |
| 69 if (!canvas_playback_rect.IsEmpty() && | 68 if (!canvas_playback_rect.IsEmpty() && |
| 70 !raster_bounds.intersect(gfx::RectToSkIRect(canvas_playback_rect))) | 69 !raster_bounds.intersect(gfx::RectToSkIRect(canvas_playback_rect))) |
| 71 return; | 70 return; |
| 72 // Treat all subnormal values as zero for performance. | 71 // Treat all subnormal values as zero for performance. |
| 73 ScopedSubnormalFloatDisabler disabler; | 72 ScopedSubnormalFloatDisabler disabler; |
| 74 | 73 |
| 75 raster_canvas->save(); | 74 raster_canvas->save(); |
| 76 raster_canvas->translate(-canvas_bitmap_rect.x(), -canvas_bitmap_rect.y()); | 75 raster_canvas->translate(-canvas_bitmap_rect.x(), -canvas_bitmap_rect.y()); |
| 77 raster_canvas->clipRect(SkRect::MakeFromIRect(raster_bounds)); | 76 raster_canvas->clipRect(SkRect::MakeFromIRect(raster_bounds)); |
| 78 raster_canvas->scale(raster_scale, raster_scale); | 77 raster_canvas->scale(raster_scale, raster_scale); |
| 79 PlaybackToCanvas(raster_canvas, settings); | 78 PlaybackToCanvas(raster_canvas, settings); |
| 80 raster_canvas->restore(); | 79 raster_canvas->restore(); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas, | 82 void RasterSource::PlaybackToCanvas(PaintCanvas* raster_canvas, |
| 84 const PlaybackSettings& settings) const { | 83 const PlaybackSettings& settings) const { |
| 85 if (!settings.playback_to_shared_canvas) | 84 if (!settings.playback_to_shared_canvas) |
| 86 PrepareForPlaybackToCanvas(raster_canvas); | 85 PrepareForPlaybackToCanvas(raster_canvas); |
| 87 | 86 |
| 88 if (settings.skip_images) { | 87 if (settings.skip_images) { |
| 89 SkipImageCanvas canvas(raster_canvas); | 88 SkipImageCanvas canvas(raster_canvas); |
| 90 RasterCommon(&canvas, nullptr); | 89 RasterCommon(&canvas, nullptr); |
| 91 } else if (settings.use_image_hijack_canvas) { | 90 } else if (settings.use_image_hijack_canvas) { |
| 92 const SkImageInfo& info = raster_canvas->imageInfo(); | 91 const SkImageInfo& info = raster_canvas->imageInfo(); |
| 93 | 92 |
| 94 ImageHijackCanvas canvas(info.width(), info.height(), image_decode_cache_); | 93 ImageHijackCanvas canvas(info.width(), info.height(), image_decode_cache_); |
| 95 // Before adding the canvas, make sure that the ImageHijackCanvas is aware | 94 // Before adding the canvas, make sure that the ImageHijackCanvas is aware |
| 96 // of the current transform and clip, which may affect the clip bounds. | 95 // of the current transform and clip, which may affect the clip bounds. |
| 97 // Since we query the clip bounds of the current canvas to get the list of | 96 // Since we query the clip bounds of the current canvas to get the list of |
| 98 // draw commands to process, this is important to produce correct content. | 97 // draw commands to process, this is important to produce correct content. |
| 99 SkIRect raster_bounds; | 98 SkIRect raster_bounds; |
| 100 raster_canvas->getClipDeviceBounds(&raster_bounds); | 99 raster_canvas->getClipDeviceBounds(&raster_bounds); |
| 101 canvas.clipRect(SkRect::MakeFromIRect(raster_bounds)); | 100 canvas.clipRect(SkRect::MakeFromIRect(raster_bounds)); |
| 102 canvas.setMatrix(raster_canvas->getTotalMatrix()); | 101 canvas.setMatrix(raster_canvas->getTotalMatrix()); |
| 103 canvas.addCanvas(raster_canvas); | 102 canvas.addCanvas(raster_canvas); |
| 104 | 103 |
| 105 RasterCommon(&canvas, nullptr); | 104 RasterCommon(&canvas, nullptr); |
| 106 } else { | 105 } else { |
| 107 RasterCommon(raster_canvas, nullptr); | 106 RasterCommon(raster_canvas, nullptr); |
| 108 } | 107 } |
| 109 } | 108 } |
| 110 | 109 |
| 111 namespace { | 110 namespace { |
| 112 | 111 |
| 113 bool CanvasIsUnclipped(const SkCanvas* canvas) { | 112 bool CanvasIsUnclipped(const PaintCanvas* canvas) { |
| 114 if (!canvas->isClipRect()) | 113 if (!canvas->isClipRect()) |
| 115 return false; | 114 return false; |
| 116 | 115 |
| 117 SkIRect bounds; | 116 SkIRect bounds; |
| 118 if (!canvas->getClipDeviceBounds(&bounds)) | 117 if (!canvas->getClipDeviceBounds(&bounds)) |
| 119 return false; | 118 return false; |
| 120 | 119 |
| 121 SkISize size = canvas->getBaseLayerSize(); | 120 SkISize size = canvas->getBaseLayerSize(); |
| 122 return bounds.contains(0, 0, size.width(), size.height()); | 121 return bounds.contains(0, 0, size.width(), size.height()); |
| 123 } | 122 } |
| 124 | 123 |
| 125 } // namespace | 124 } // namespace |
| 126 | 125 |
| 127 void RasterSource::PrepareForPlaybackToCanvas(SkCanvas* canvas) const { | 126 void RasterSource::PrepareForPlaybackToCanvas(PaintCanvas* canvas) const { |
| 128 // TODO(hendrikw): See if we can split this up into separate functions. | 127 // TODO(hendrikw): See if we can split this up into separate functions. |
| 129 | 128 |
| 130 if (CanvasIsUnclipped(canvas)) | 129 if (CanvasIsUnclipped(canvas)) |
| 131 canvas->discard(); | 130 canvas->discard(); |
| 132 | 131 |
| 133 // If this raster source has opaque contents, it is guaranteeing that it will | 132 // If this raster source has opaque contents, it is guaranteeing that it will |
| 134 // draw an opaque rect the size of the layer. If it is not, then we must | 133 // draw an opaque rect the size of the layer. If it is not, then we must |
| 135 // clear this canvas ourselves. | 134 // clear this canvas ourselves. |
| 136 if (requires_clear_) { | 135 if (requires_clear_) { |
| 137 canvas->clear(SK_ColorTRANSPARENT); | 136 canvas->clear(SK_ColorTRANSPARENT); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 canvas->save(); | 192 canvas->save(); |
| 194 // Use clipRegion to bypass CTM because the rects are device rects. | 193 // Use clipRegion to bypass CTM because the rects are device rects. |
| 195 SkRegion interest_region; | 194 SkRegion interest_region; |
| 196 interest_region.setRect(interest_rect); | 195 interest_region.setRect(interest_rect); |
| 197 interest_region.op(opaque_rect, SkRegion::kDifference_Op); | 196 interest_region.op(opaque_rect, SkRegion::kDifference_Op); |
| 198 canvas->clipRegion(interest_region); | 197 canvas->clipRegion(interest_region); |
| 199 canvas->clear(background_color_); | 198 canvas->clear(background_color_); |
| 200 canvas->restore(); | 199 canvas->restore(); |
| 201 } | 200 } |
| 202 | 201 |
| 203 void RasterSource::RasterCommon(SkCanvas* canvas, | 202 void RasterSource::RasterCommon(PaintCanvas* canvas, |
| 204 SkPicture::AbortCallback* callback) const { | 203 PaintRecord::AbortCallback* callback) const { |
| 205 DCHECK(display_list_.get()); | 204 DCHECK(display_list_.get()); |
| 206 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); | 205 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); |
| 207 for (int i = 0; i < repeat_count; ++i) | 206 for (int i = 0; i < repeat_count; ++i) |
| 208 display_list_->Raster(canvas, callback); | 207 display_list_->Raster(canvas, callback); |
| 209 } | 208 } |
| 210 | 209 |
| 211 sk_sp<SkPicture> RasterSource::GetFlattenedPicture() { | 210 sk_sp<PaintRecord> RasterSource::GetFlattenedPicture() { |
| 212 TRACE_EVENT0("cc", "RasterSource::GetFlattenedPicture"); | 211 TRACE_EVENT0("cc", "RasterSource::GetFlattenedPicture"); |
| 213 | 212 |
| 214 SkPictureRecorder recorder; | 213 PaintRecorder recorder; |
| 215 SkCanvas* canvas = recorder.beginRecording(size_.width(), size_.height()); | 214 PaintCanvas* canvas = recorder.beginRecording(size_.width(), size_.height()); |
| 216 if (!size_.IsEmpty()) { | 215 if (!size_.IsEmpty()) { |
| 217 PrepareForPlaybackToCanvas(canvas); | 216 PrepareForPlaybackToCanvas(canvas); |
| 218 RasterCommon(canvas, nullptr); | 217 RasterCommon(canvas, nullptr); |
| 219 } | 218 } |
| 220 | 219 |
| 221 return recorder.finishRecordingAsPicture(); | 220 return recorder.finishRecordingAsPicture(); |
| 222 } | 221 } |
| 223 | 222 |
| 224 size_t RasterSource::GetPictureMemoryUsage() const { | 223 size_t RasterSource::GetPictureMemoryUsage() const { |
| 225 if (!display_list_) | 224 if (!display_list_) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 bool can_use_lcd_text = false; | 305 bool can_use_lcd_text = false; |
| 307 return scoped_refptr<RasterSource>(new RasterSource(this, can_use_lcd_text)); | 306 return scoped_refptr<RasterSource>(new RasterSource(this, can_use_lcd_text)); |
| 308 } | 307 } |
| 309 | 308 |
| 310 RasterSource::PlaybackSettings::PlaybackSettings() | 309 RasterSource::PlaybackSettings::PlaybackSettings() |
| 311 : playback_to_shared_canvas(false), | 310 : playback_to_shared_canvas(false), |
| 312 skip_images(false), | 311 skip_images(false), |
| 313 use_image_hijack_canvas(true) {} | 312 use_image_hijack_canvas(true) {} |
| 314 | 313 |
| 315 } // namespace cc | 314 } // namespace cc |
| OLD | NEW |