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

Side by Side Diff: cc/playback/raster_source.cc

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

Powered by Google App Engine
This is Rietveld 408576698