| 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/playback/display_item_list.h" | 13 #include "cc/playback/display_item_list.h" |
| 14 #include "cc/playback/image_hijack_canvas.h" | 14 #include "cc/playback/image_hijack_canvas.h" |
| 15 #include "cc/playback/skip_image_canvas.h" | 15 #include "cc/playback/skip_image_canvas.h" |
| 16 #include "skia/ext/analysis_canvas.h" | 16 #include "skia/ext/analysis_canvas.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "skia/ext/cdl_canvas.h" |
| 18 #include "third_party/skia/include/core/SkClipStack.h" | 18 #include "third_party/skia/include/core/SkClipStack.h" |
| 19 #include "third_party/skia/include/core/SkPictureRecorder.h" | 19 #include "skia/ext/cdl_picture_recorder.h" |
| 20 #include "ui/gfx/geometry/rect_conversions.h" | 20 #include "ui/gfx/geometry/rect_conversions.h" |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 | 23 |
| 24 scoped_refptr<RasterSource> RasterSource::CreateFromRecordingSource( | 24 scoped_refptr<RasterSource> RasterSource::CreateFromRecordingSource( |
| 25 const RecordingSource* other, | 25 const RecordingSource* other, |
| 26 bool can_use_lcd_text) { | 26 bool can_use_lcd_text) { |
| 27 return make_scoped_refptr(new RasterSource(other, can_use_lcd_text)); | 27 return make_scoped_refptr(new RasterSource(other, can_use_lcd_text)); |
| 28 } | 28 } |
| 29 | 29 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 raster_canvas->save(); | 78 raster_canvas->save(); |
| 79 raster_canvas->translate(-canvas_bitmap_rect.x(), -canvas_bitmap_rect.y()); | 79 raster_canvas->translate(-canvas_bitmap_rect.x(), -canvas_bitmap_rect.y()); |
| 80 raster_canvas->clipRect(SkRect::MakeFromIRect(raster_bounds)); | 80 raster_canvas->clipRect(SkRect::MakeFromIRect(raster_bounds)); |
| 81 raster_canvas->scale(raster_scales.width(), raster_scales.height()); | 81 raster_canvas->scale(raster_scales.width(), raster_scales.height()); |
| 82 PlaybackToCanvas(raster_canvas, settings); | 82 PlaybackToCanvas(raster_canvas, settings); |
| 83 raster_canvas->restore(); | 83 raster_canvas->restore(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas, | 86 void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas, |
| 87 const PlaybackSettings& settings) const { | 87 const PlaybackSettings& settings) const { |
| 88 if (!settings.playback_to_shared_canvas) | 88 std::unique_ptr<CdlCanvas> playback_canvas; |
| 89 PrepareForPlaybackToCanvas(raster_canvas); | |
| 90 | 89 |
| 91 if (settings.skip_images) { | 90 if (settings.skip_images) { |
| 92 SkipImageCanvas canvas(raster_canvas); | 91 // TODO(cdl): SkipImageCanvas |
| 93 RasterCommon(&canvas, nullptr); | 92 // SkipImageCanvas canvas(raster_canvas); |
| 93 // RasterCommon(&canvas, nullptr); |
| 94 playback_canvas.reset(new CdlPassThroughCanvas(raster_canvas)); |
| 94 } else if (settings.use_image_hijack_canvas) { | 95 } else if (settings.use_image_hijack_canvas) { |
| 95 const SkImageInfo& info = raster_canvas->imageInfo(); | 96 playback_canvas.reset( |
| 97 new ImageHijackCanvas(raster_canvas, image_decode_cache_)); |
| 98 } else { |
| 99 playback_canvas.reset(new CdlPassThroughCanvas(raster_canvas)); |
| 100 } |
| 96 | 101 |
| 97 ImageHijackCanvas canvas(info.width(), info.height(), image_decode_cache_); | 102 if (!settings.playback_to_shared_canvas) |
| 98 // Before adding the canvas, make sure that the ImageHijackCanvas is aware | 103 PrepareForPlaybackToCanvas(playback_canvas.get()); |
| 99 // of the current transform and clip, which may affect the clip bounds. | |
| 100 // Since we query the clip bounds of the current canvas to get the list of | |
| 101 // draw commands to process, this is important to produce correct content. | |
| 102 SkIRect raster_bounds; | |
| 103 raster_canvas->getClipDeviceBounds(&raster_bounds); | |
| 104 canvas.clipRect(SkRect::MakeFromIRect(raster_bounds)); | |
| 105 canvas.setMatrix(raster_canvas->getTotalMatrix()); | |
| 106 canvas.addCanvas(raster_canvas); | |
| 107 | 104 |
| 108 RasterCommon(&canvas, nullptr); | 105 RasterCommon(playback_canvas.get(), nullptr); |
| 109 } else { | |
| 110 RasterCommon(raster_canvas, nullptr); | |
| 111 } | |
| 112 } | 106 } |
| 113 | 107 |
| 114 void RasterSource::PrepareForPlaybackToCanvas(SkCanvas* canvas) const { | 108 void RasterSource::PrepareForPlaybackToCanvas(CdlCanvas* canvas) const { |
| 115 // TODO(hendrikw): See if we can split this up into separate functions. | 109 // TODO(hendrikw): See if we can split this up into separate functions. |
| 116 | 110 |
| 117 if (canvas->getClipStack()->quickContains( | 111 if (canvas->getClipStack()->quickContains( |
| 118 SkRect::MakeFromIRect(canvas->imageInfo().bounds()))) { | 112 SkRect::MakeFromIRect(GetSkCanvas(canvas)->imageInfo().bounds()))) { |
| 119 canvas->discard(); | 113 canvas->discard(); |
| 120 } | 114 } |
| 121 | 115 |
| 122 // If this raster source has opaque contents, it is guaranteeing that it will | 116 // If this raster source has opaque contents, it is guaranteeing that it will |
| 123 // draw an opaque rect the size of the layer. If it is not, then we must | 117 // draw an opaque rect the size of the layer. If it is not, then we must |
| 124 // clear this canvas ourselves. | 118 // clear this canvas ourselves. |
| 125 if (requires_clear_) { | 119 if (requires_clear_) { |
| 126 canvas->clear(SK_ColorTRANSPARENT); | 120 canvas->clear(SK_ColorTRANSPARENT); |
| 127 return; | 121 return; |
| 128 } | 122 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 canvas->save(); | 176 canvas->save(); |
| 183 // Use clipRegion to bypass CTM because the rects are device rects. | 177 // Use clipRegion to bypass CTM because the rects are device rects. |
| 184 SkRegion interest_region; | 178 SkRegion interest_region; |
| 185 interest_region.setRect(interest_rect); | 179 interest_region.setRect(interest_rect); |
| 186 interest_region.op(opaque_rect, SkRegion::kDifference_Op); | 180 interest_region.op(opaque_rect, SkRegion::kDifference_Op); |
| 187 canvas->clipRegion(interest_region); | 181 canvas->clipRegion(interest_region); |
| 188 canvas->clear(background_color_); | 182 canvas->clear(background_color_); |
| 189 canvas->restore(); | 183 canvas->restore(); |
| 190 } | 184 } |
| 191 | 185 |
| 192 void RasterSource::RasterCommon(SkCanvas* canvas, | 186 void RasterSource::RasterCommon(CdlCanvas* canvas, |
| 193 SkPicture::AbortCallback* callback) const { | 187 SkPicture::AbortCallback* callback) const { |
| 194 DCHECK(display_list_.get()); | 188 DCHECK(display_list_.get()); |
| 195 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); | 189 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); |
| 196 for (int i = 0; i < repeat_count; ++i) | 190 for (int i = 0; i < repeat_count; ++i) |
| 197 display_list_->Raster(canvas, callback); | 191 display_list_->Raster(canvas, callback); |
| 198 } | 192 } |
| 199 | 193 |
| 200 sk_sp<SkPicture> RasterSource::GetFlattenedPicture() { | 194 sk_sp<CdlPicture> RasterSource::GetFlattenedPicture() { |
| 201 TRACE_EVENT0("cc", "RasterSource::GetFlattenedPicture"); | 195 TRACE_EVENT0("cc", "RasterSource::GetFlattenedPicture"); |
| 202 | 196 |
| 203 SkPictureRecorder recorder; | 197 CdlPictureRecorder recorder; |
| 204 SkCanvas* canvas = recorder.beginRecording(size_.width(), size_.height()); | 198 CdlCanvas* canvas = recorder.beginRecording(size_.width(), size_.height()); |
| 205 if (!size_.IsEmpty()) { | 199 if (!size_.IsEmpty()) { |
| 206 PrepareForPlaybackToCanvas(canvas); | 200 PrepareForPlaybackToCanvas(canvas); |
| 207 RasterCommon(canvas, nullptr); | 201 RasterCommon(canvas, nullptr); |
| 208 } | 202 } |
| 209 | 203 |
| 210 return recorder.finishRecordingAsPicture(); | 204 return recorder.finishRecordingAsPicture(); |
| 211 } | 205 } |
| 212 | 206 |
| 213 size_t RasterSource::GetPictureMemoryUsage() const { | 207 size_t RasterSource::GetPictureMemoryUsage() const { |
| 214 if (!display_list_) | 208 if (!display_list_) |
| 215 return 0; | 209 return 0; |
| 216 return display_list_->ApproximateMemoryUsage() + | 210 return display_list_->ApproximateMemoryUsage() + |
| 217 painter_reported_memory_usage_; | 211 painter_reported_memory_usage_; |
| 218 } | 212 } |
| 219 | 213 |
| 220 bool RasterSource::PerformSolidColorAnalysis(const gfx::Rect& content_rect, | 214 bool RasterSource::PerformSolidColorAnalysis(const gfx::Rect& content_rect, |
| 221 const gfx::SizeF& raster_scales, | 215 const gfx::SizeF& raster_scales, |
| 222 SkColor* color) const { | 216 SkColor* color) const { |
| 223 TRACE_EVENT0("cc", "RasterSource::PerformSolidColorAnalysis"); | 217 TRACE_EVENT0("cc", "RasterSource::PerformSolidColorAnalysis"); |
| 224 | 218 |
| 225 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( | 219 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( |
| 226 content_rect, 1.f / raster_scales.width(), 1.f / raster_scales.height()); | 220 content_rect, 1.f / raster_scales.width(), 1.f / raster_scales.height()); |
| 227 | 221 |
| 228 layer_rect.Intersect(gfx::Rect(size_)); | 222 layer_rect.Intersect(gfx::Rect(size_)); |
| 229 skia::AnalysisCanvas canvas(layer_rect.width(), layer_rect.height()); | 223 skia::AnalysisCanvas sk_canvas(layer_rect.width(), layer_rect.height()); |
| 224 CdlPassThroughCanvas canvas(&sk_canvas); |
| 230 canvas.translate(-layer_rect.x(), -layer_rect.y()); | 225 canvas.translate(-layer_rect.x(), -layer_rect.y()); |
| 231 RasterCommon(&canvas, &canvas); | 226 RasterCommon(&canvas, &sk_canvas); |
| 232 return canvas.GetColorIfSolid(color); | 227 return sk_canvas.GetColorIfSolid(color); |
| 233 } | 228 } |
| 234 | 229 |
| 235 void RasterSource::GetDiscardableImagesInRect( | 230 void RasterSource::GetDiscardableImagesInRect( |
| 236 const gfx::Rect& layer_rect, | 231 const gfx::Rect& layer_rect, |
| 237 const gfx::SizeF& raster_scales, | 232 const gfx::SizeF& raster_scales, |
| 238 std::vector<DrawImage>* images) const { | 233 std::vector<DrawImage>* images) const { |
| 239 DCHECK_EQ(0u, images->size()); | 234 DCHECK_EQ(0u, images->size()); |
| 240 display_list_->GetDiscardableImagesInRect(layer_rect, raster_scales, images); | 235 display_list_->GetDiscardableImagesInRect(layer_rect, raster_scales, images); |
| 241 } | 236 } |
| 242 | 237 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 bool can_use_lcd_text = false; | 298 bool can_use_lcd_text = false; |
| 304 return scoped_refptr<RasterSource>(new RasterSource(this, can_use_lcd_text)); | 299 return scoped_refptr<RasterSource>(new RasterSource(this, can_use_lcd_text)); |
| 305 } | 300 } |
| 306 | 301 |
| 307 RasterSource::PlaybackSettings::PlaybackSettings() | 302 RasterSource::PlaybackSettings::PlaybackSettings() |
| 308 : playback_to_shared_canvas(false), | 303 : playback_to_shared_canvas(false), |
| 309 skip_images(false), | 304 skip_images(false), |
| 310 use_image_hijack_canvas(true) {} | 305 use_image_hijack_canvas(true) {} |
| 311 | 306 |
| 312 } // namespace cc | 307 } // namespace cc |
| OLD | NEW |