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

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

Issue 1385733002: (not for review) nwayover (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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/playback/display_list_raster_source.h ('k') | cc/playback/position_image.h » ('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 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/display_list_raster_source.h" 5 #include "cc/playback/display_list_raster_source.h"
6 6
7 #include "base/trace_event/trace_event.h" 7 #include "base/trace_event/trace_event.h"
8 #include "cc/base/region.h" 8 #include "cc/base/region.h"
9 #include "cc/debug/debug_colors.h" 9 #include "cc/debug/debug_colors.h"
10 #include "cc/playback/display_item_list.h" 10 #include "cc/playback/display_item_list.h"
11 #include "cc/playback/raster_source_helper.h" 11 #include "cc/playback/raster_source_helper.h"
12 #include "cc/tiles/image_decode_controller.h"
12 #include "skia/ext/analysis_canvas.h" 13 #include "skia/ext/analysis_canvas.h"
13 #include "third_party/skia/include/core/SkCanvas.h" 14 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/core/SkPictureRecorder.h" 15 #include "third_party/skia/include/core/SkPictureRecorder.h"
16 #include "third_party/skia/include/utils/SkNWayCanvas.h"
15 #include "ui/gfx/geometry/rect_conversions.h" 17 #include "ui/gfx/geometry/rect_conversions.h"
16 18
17 namespace cc { 19 namespace cc {
18 20
21 namespace {
22
23 SkRect MapRect(const SkMatrix& matrix, const SkRect& src) {
24 SkRect dst;
25 matrix.mapRect(&dst, src);
26 return dst;
27 }
28
29 class ImageHijackCanvas : public SkNWayCanvas {
30 public:
31 ImageHijackCanvas(int width,
32 int height,
33 ImageDecodeController* image_decode_controller)
34 : SkNWayCanvas(width, height),
35 image_decode_controller_(image_decode_controller),
36 canvas_bounds_(SkRect::MakeIWH(width, height)) {}
37
38 protected:
39 // Ensure that pictures are unpacked by this canvas, instead of being
40 // forwarded to the raster canvas.
41 void onDrawPicture(const SkPicture* picture,
42 const SkMatrix* matrix,
43 const SkPaint* paint) override {
44 SkCanvas::onDrawPicture(picture, matrix, paint);
45 }
46
47 void onDrawImage(const SkImage* image,
48 SkScalar x,
49 SkScalar y,
50 const SkPaint* paint) override {
51 SkMatrix ctm = this->getTotalMatrix();
52 DecodedPositionImage decoded_image = LookupImage(
53 image,
54 MapRect(ctm, SkRect::MakeXYWH(x, y, image->width(), image->height())),
55 ctm, paint);
56
57 SkPaint decoded_paint;
58 if (paint) {
59 decoded_paint = *paint;
60 decoded_paint.setFilterQuality(decoded_image.filter_quality);
61 }
62
63 SkNWayCanvas::save();
64 ctm.postScale(decoded_image.scale_adjustment.width(),
65 decoded_image.scale_adjustment.height());
66 SkNWayCanvas::setMatrix(ctm);
67 SkNWayCanvas::onDrawImage(decoded_image.image, x, y,
68 paint ? &decoded_paint : nullptr);
69 SkNWayCanvas::restore();
70 }
71
72 void onDrawImageRect(const SkImage* image,
73 const SkRect* src,
74 const SkRect& dst,
75 const SkPaint* paint,
76 SrcRectConstraint constraint) override {
77 SkMatrix ctm = this->getTotalMatrix();
78 SkRect src_storage;
79 if (!src) {
80 src_storage = SkRect::MakeIWH(image->width(), image->height());
81 src = &src_storage;
82 }
83 SkMatrix matrix;
84 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit);
85 matrix.postConcat(ctm);
86 DecodedPositionImage decoded_image =
87 LookupImage(image, MapRect(ctm, dst), matrix, paint);
88 SkPaint decoded_paint;
89 if (paint) {
90 decoded_paint = *paint;
91 decoded_paint.setFilterQuality(decoded_image.filter_quality);
92 }
93 float x_scale = decoded_image.scale_adjustment.width();
94 float y_scale = decoded_image.scale_adjustment.height();
95 SkRect adjusted_src =
96 SkRect::MakeXYWH(src->x() * x_scale, src->y() * y_scale,
97 src->width() * x_scale, src->height() * y_scale);
98 SkNWayCanvas::onDrawImageRect(decoded_image.image, &adjusted_src, dst,
99 paint ? &decoded_paint : nullptr, constraint);
100 }
101
102 void onDrawImageNine(const SkImage* image,
103 const SkIRect& center,
104 const SkRect& dst,
105 const SkPaint* paint) override {
106 SkMatrix ctm = this->getTotalMatrix();
107 DecodedPositionImage decoded_image = LookupImage(image, dst, ctm, paint);
108 SkPaint decoded_paint;
109 if (paint) {
110 decoded_paint = *paint;
111 decoded_paint.setFilterQuality(decoded_image.filter_quality);
112 }
113 float x_scale = decoded_image.scale_adjustment.width();
114 float y_scale = decoded_image.scale_adjustment.height();
115 SkIRect adjusted_center = SkIRect::MakeXYWH(
116 static_cast<int>(std::floor(center.x() * x_scale)),
117 static_cast<int>(std::floor(center.y() * y_scale)),
118 static_cast<int>(std::ceil(center.width() * x_scale)),
119 static_cast<int>(std::ceil(center.height() * y_scale)));
120 SkNWayCanvas::onDrawImageNine(decoded_image.image, adjusted_center, dst,
121 paint ? &decoded_paint : paint);
122 }
123
124 private:
125 DecodedPositionImage LookupImage(const SkImage* image,
126 const SkRect& rect,
127 const SkMatrix& matrix,
128 const SkPaint* paint) {
129 SkFilterQuality filter_quality = kNone_SkFilterQuality;
130 if (paint)
131 filter_quality = paint->getFilterQuality();
132
133 if (rect.intersects(canvas_bounds_) && image->isLazyGenerated()) {
134 return image_decode_controller_->GetDecodedImage(
135 PositionImage(image, rect, matrix, filter_quality));
136 }
137 return DecodedPositionImage(image, SkSize::Make(1.f, 1.f), filter_quality);
138 }
139
140 ImageDecodeController* image_decode_controller_;
141 const SkRect canvas_bounds_;
142 };
143
144 } // namespace
145
19 scoped_refptr<DisplayListRasterSource> 146 scoped_refptr<DisplayListRasterSource>
20 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 147 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
21 const DisplayListRecordingSource* other, 148 const DisplayListRecordingSource* other,
22 bool can_use_lcd_text) { 149 bool can_use_lcd_text) {
23 return make_scoped_refptr( 150 return make_scoped_refptr(
24 new DisplayListRasterSource(other, can_use_lcd_text)); 151 new DisplayListRasterSource(other, can_use_lcd_text));
25 } 152 }
26 153
27 DisplayListRasterSource::DisplayListRasterSource() 154 DisplayListRasterSource::DisplayListRasterSource()
28 : painter_reported_memory_usage_(0), 155 : painter_reported_memory_usage_(0),
29 background_color_(SK_ColorTRANSPARENT), 156 background_color_(SK_ColorTRANSPARENT),
30 requires_clear_(true), 157 requires_clear_(true),
31 can_use_lcd_text_(true), 158 can_use_lcd_text_(true),
32 is_solid_color_(false), 159 is_solid_color_(false),
33 solid_color_(SK_ColorTRANSPARENT), 160 solid_color_(SK_ColorTRANSPARENT),
34 clear_canvas_with_debug_color_(false), 161 clear_canvas_with_debug_color_(false),
35 slow_down_raster_scale_factor_for_debug_(0), 162 slow_down_raster_scale_factor_for_debug_(0),
36 should_attempt_to_use_distance_field_text_(false) {} 163 should_attempt_to_use_distance_field_text_(false),
164 image_decode_controller_(nullptr) {}
37 165
38 DisplayListRasterSource::DisplayListRasterSource( 166 DisplayListRasterSource::DisplayListRasterSource(
39 const DisplayListRecordingSource* other, 167 const DisplayListRecordingSource* other,
40 bool can_use_lcd_text) 168 bool can_use_lcd_text)
41 : display_list_(other->display_list_), 169 : display_list_(other->display_list_),
42 painter_reported_memory_usage_(other->painter_reported_memory_usage_), 170 painter_reported_memory_usage_(other->painter_reported_memory_usage_),
43 background_color_(other->background_color_), 171 background_color_(other->background_color_),
44 requires_clear_(other->requires_clear_), 172 requires_clear_(other->requires_clear_),
45 can_use_lcd_text_(can_use_lcd_text), 173 can_use_lcd_text_(can_use_lcd_text),
46 is_solid_color_(other->is_solid_color_), 174 is_solid_color_(other->is_solid_color_),
47 solid_color_(other->solid_color_), 175 solid_color_(other->solid_color_),
48 recorded_viewport_(other->recorded_viewport_), 176 recorded_viewport_(other->recorded_viewport_),
49 size_(other->size_), 177 size_(other->size_),
50 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), 178 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_),
51 slow_down_raster_scale_factor_for_debug_( 179 slow_down_raster_scale_factor_for_debug_(
52 other->slow_down_raster_scale_factor_for_debug_), 180 other->slow_down_raster_scale_factor_for_debug_),
53 should_attempt_to_use_distance_field_text_(false) {} 181 should_attempt_to_use_distance_field_text_(false),
182 image_decode_controller_(nullptr) {}
54 183
55 DisplayListRasterSource::DisplayListRasterSource( 184 DisplayListRasterSource::DisplayListRasterSource(
56 const DisplayListRasterSource* other, 185 const DisplayListRasterSource* other,
57 bool can_use_lcd_text) 186 bool can_use_lcd_text)
58 : display_list_(other->display_list_), 187 : display_list_(other->display_list_),
59 painter_reported_memory_usage_(other->painter_reported_memory_usage_), 188 painter_reported_memory_usage_(other->painter_reported_memory_usage_),
60 background_color_(other->background_color_), 189 background_color_(other->background_color_),
61 requires_clear_(other->requires_clear_), 190 requires_clear_(other->requires_clear_),
62 can_use_lcd_text_(can_use_lcd_text), 191 can_use_lcd_text_(can_use_lcd_text),
63 is_solid_color_(other->is_solid_color_), 192 is_solid_color_(other->is_solid_color_),
64 solid_color_(other->solid_color_), 193 solid_color_(other->solid_color_),
65 recorded_viewport_(other->recorded_viewport_), 194 recorded_viewport_(other->recorded_viewport_),
66 size_(other->size_), 195 size_(other->size_),
67 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), 196 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_),
68 slow_down_raster_scale_factor_for_debug_( 197 slow_down_raster_scale_factor_for_debug_(
69 other->slow_down_raster_scale_factor_for_debug_), 198 other->slow_down_raster_scale_factor_for_debug_),
70 should_attempt_to_use_distance_field_text_( 199 should_attempt_to_use_distance_field_text_(
71 other->should_attempt_to_use_distance_field_text_) {} 200 other->should_attempt_to_use_distance_field_text_),
201 image_decode_controller_(other->image_decode_controller_) {}
72 202
73 DisplayListRasterSource::~DisplayListRasterSource() { 203 DisplayListRasterSource::~DisplayListRasterSource() {
74 } 204 }
75 205
76 void DisplayListRasterSource::PlaybackToSharedCanvas( 206 void DisplayListRasterSource::PlaybackToSharedCanvas(
77 SkCanvas* canvas, 207 SkCanvas* canvas,
78 const gfx::Rect& canvas_rect, 208 const gfx::Rect& canvas_rect,
79 float contents_scale) const { 209 float contents_scale) const {
80 RasterCommon(canvas, NULL, canvas_rect, canvas_rect, contents_scale); 210 RasterCommon(canvas, NULL, canvas_rect, canvas_rect, contents_scale);
81 } 211 }
(...skipping 12 matching lines...) Expand all
94 RasterSourceHelper::PrepareForPlaybackToCanvas( 224 RasterSourceHelper::PrepareForPlaybackToCanvas(
95 canvas, canvas_bitmap_rect, canvas_playback_rect, gfx::Rect(size_), 225 canvas, canvas_bitmap_rect, canvas_playback_rect, gfx::Rect(size_),
96 contents_scale, background_color_, clear_canvas_with_debug_color_, 226 contents_scale, background_color_, clear_canvas_with_debug_color_,
97 requires_clear_); 227 requires_clear_);
98 228
99 RasterCommon(canvas, NULL, canvas_bitmap_rect, canvas_playback_rect, 229 RasterCommon(canvas, NULL, canvas_bitmap_rect, canvas_playback_rect,
100 contents_scale); 230 contents_scale);
101 } 231 }
102 232
103 void DisplayListRasterSource::RasterCommon( 233 void DisplayListRasterSource::RasterCommon(
104 SkCanvas* canvas, 234 SkCanvas* raster_canvas,
105 SkPicture::AbortCallback* callback, 235 SkPicture::AbortCallback* callback,
106 const gfx::Rect& canvas_bitmap_rect, 236 const gfx::Rect& canvas_bitmap_rect,
107 const gfx::Rect& canvas_playback_rect, 237 const gfx::Rect& canvas_playback_rect,
108 float contents_scale) const { 238 float contents_scale) const {
109 canvas->translate(-canvas_bitmap_rect.x(), -canvas_bitmap_rect.y()); 239 SkImageInfo info = raster_canvas->imageInfo();
240 ImageHijackCanvas canvas(info.width(), info.height(),
241 image_decode_controller_);
242 canvas.addCanvas(raster_canvas);
243
244 canvas.translate(-canvas_bitmap_rect.x(), -canvas_bitmap_rect.y());
110 gfx::Rect content_rect = 245 gfx::Rect content_rect =
111 gfx::ScaleToEnclosingRect(gfx::Rect(size_), contents_scale); 246 gfx::ScaleToEnclosingRect(gfx::Rect(size_), contents_scale);
112 content_rect.Intersect(canvas_playback_rect); 247 content_rect.Intersect(canvas_playback_rect);
113 248
114 canvas->clipRect(gfx::RectToSkRect(content_rect), SkRegion::kIntersect_Op); 249 canvas.clipRect(gfx::RectToSkRect(content_rect), SkRegion::kIntersect_Op);
115 250
116 DCHECK(display_list_.get()); 251 DCHECK(display_list_.get());
117 gfx::Rect canvas_target_playback_rect = 252 gfx::Rect canvas_target_playback_rect =
118 canvas_playback_rect - canvas_bitmap_rect.OffsetFromOrigin(); 253 canvas_playback_rect - canvas_bitmap_rect.OffsetFromOrigin();
119 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); 254 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_);
120 for (int i = 0; i < repeat_count; ++i) { 255 for (int i = 0; i < repeat_count; ++i) {
121 display_list_->Raster(canvas, callback, canvas_target_playback_rect, 256 display_list_->Raster(&canvas, callback, canvas_target_playback_rect,
122 contents_scale); 257 contents_scale);
123 } 258 }
124 } 259 }
125 260
126 skia::RefPtr<SkPicture> DisplayListRasterSource::GetFlattenedPicture() { 261 skia::RefPtr<SkPicture> DisplayListRasterSource::GetFlattenedPicture() {
127 TRACE_EVENT0("cc", "DisplayListRasterSource::GetFlattenedPicture"); 262 TRACE_EVENT0("cc", "DisplayListRasterSource::GetFlattenedPicture");
128 263
129 gfx::Rect display_list_rect(size_); 264 gfx::Rect display_list_rect(size_);
130 SkPictureRecorder recorder; 265 SkPictureRecorder recorder;
131 SkCanvas* canvas = recorder.beginRecording(display_list_rect.width(), 266 SkCanvas* canvas = recorder.beginRecording(display_list_rect.width(),
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 return can_use_lcd_text_; 355 return can_use_lcd_text_;
221 } 356 }
222 357
223 scoped_refptr<RasterSource> DisplayListRasterSource::CreateCloneWithoutLCDText() 358 scoped_refptr<RasterSource> DisplayListRasterSource::CreateCloneWithoutLCDText()
224 const { 359 const {
225 bool can_use_lcd_text = false; 360 bool can_use_lcd_text = false;
226 return scoped_refptr<RasterSource>( 361 return scoped_refptr<RasterSource>(
227 new DisplayListRasterSource(this, can_use_lcd_text)); 362 new DisplayListRasterSource(this, can_use_lcd_text));
228 } 363 }
229 364
365 void DisplayListRasterSource::SetImageDecodeController(
366 ImageDecodeController* image_decode_controller) {
367 image_decode_controller_ = image_decode_controller;
368 }
369
230 } // namespace cc 370 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/display_list_raster_source.h ('k') | cc/playback/position_image.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698