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

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

Issue 1418573002: cc: Add image decode control in the compositor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 5 years 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/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/discardable_image_map.h"
10 #include "cc/playback/display_item_list.h" 11 #include "cc/playback/display_item_list.h"
12 #include "cc/tiles/image_decode_controller.h"
11 #include "skia/ext/analysis_canvas.h" 13 #include "skia/ext/analysis_canvas.h"
12 #include "third_party/skia/include/core/SkCanvas.h" 14 #include "third_party/skia/include/core/SkCanvas.h"
13 #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"
14 #include "ui/gfx/geometry/rect_conversions.h" 17 #include "ui/gfx/geometry/rect_conversions.h"
15 18
16 namespace cc { 19 namespace cc {
17 20
21 namespace {
22
23 bool ComputePaintBounds(const SkRect& rect,
24 const SkPaint* paint,
25 SkRect* paint_bounds) {
26 return false;
vmpstr 2015/12/04 01:05:54 This is debug code :D
27 if (!paint) {
28 *paint_bounds = rect;
29 return true;
30 }
31
32 bool can_compute_bounds = paint->canComputeFastBounds();
33 if (can_compute_bounds)
34 *paint_bounds = paint->computeFastBounds(rect, paint_bounds);
35 return can_compute_bounds;
36 }
37
38 class ImageHijackCanvas : public SkNWayCanvas {
39 public:
40 ImageHijackCanvas(int width,
41 int height,
42 ImageDecodeController* image_decode_controller)
43 : SkNWayCanvas(width, height),
44 image_decode_controller_(image_decode_controller),
45 canvas_bounds_(SkRect::MakeIWH(width, height)) {}
46
47 protected:
48 // Ensure that pictures are unpacked by this canvas, instead of being
49 // forwarded to the raster canvas.
50 void onDrawPicture(const SkPicture* picture,
51 const SkMatrix* matrix,
52 const SkPaint* paint) override {
53 SkCanvas::onDrawPicture(picture, matrix, paint);
54 }
55
56 void onDrawImage(const SkImage* image,
57 SkScalar x,
58 SkScalar y,
59 const SkPaint* paint) override {
60 if (!image->isLazyGenerated()) {
61 SkNWayCanvas::onDrawImage(image, x, y, paint);
62 return;
63 }
64
65 SkMatrix ctm = this->getTotalMatrix();
ericrk 2015/12/04 00:50:46 why this? skia leaking in?
66 SkRect paint_bounds;
67 bool computed_paint_bounds = ComputePaintBounds(
68 SkRect::MakeXYWH(x, y, image->width(), image->height()), paint,
69 &paint_bounds);
70 if (computed_paint_bounds && !canvas_bounds_.intersects(paint_bounds))
71 return;
72
73 SkSize scale;
74 bool is_decomposable = ExtractScale(ctm, &scale);
75 ScopedDecodedImageLock scoped_lock(image_decode_controller_, image, scale,
76 is_decomposable, ctm.hasPerspective(),
77 paint);
78 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image();
79 const SkPaint* decoded_paint = scoped_lock.decoded_paint();
80
81 bool need_scale = !decoded_image.is_scale_adjustment_identity();
82 if (need_scale) {
83 SkNWayCanvas::save();
84 SkNWayCanvas::scale(1.f / (decoded_image.scale_adjustment().width()),
85 1.f / (decoded_image.scale_adjustment().height()));
86 }
87 SkNWayCanvas::onDrawImage(decoded_image.image(), x, y, decoded_paint);
88 if (need_scale)
89 SkNWayCanvas::restore();
90 }
91
92 void onDrawImageRect(const SkImage* image,
93 const SkRect* src,
94 const SkRect& dst,
95 const SkPaint* paint,
96 SrcRectConstraint constraint) override {
97 if (!image->isLazyGenerated()) {
98 SkNWayCanvas::onDrawImageRect(image, src, dst, paint, constraint);
99 return;
100 }
101
102 SkMatrix ctm = this->getTotalMatrix();
103 SkRect paint_bounds;
104 bool computed_paint_bounds =
105 ComputePaintBounds(MapRect(ctm, dst), paint, &paint_bounds);
106 if (computed_paint_bounds && !canvas_bounds_.intersects(paint_bounds))
107 return;
108
109 SkRect src_storage;
110 if (!src) {
111 src_storage = SkRect::MakeIWH(image->width(), image->height());
112 src = &src_storage;
113 }
114 SkMatrix matrix;
115 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit);
116 matrix.postConcat(ctm);
117
118 SkSize scale;
119 bool is_decomposable = ExtractScale(matrix, &scale);
120 ScopedDecodedImageLock scoped_lock(image_decode_controller_, image, scale,
121 is_decomposable, matrix.hasPerspective(),
122 paint);
123 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image();
124 const SkPaint* decoded_paint = scoped_lock.decoded_paint();
125
126 SkRect adjusted_src = *src;
127 if (!decoded_image.is_scale_adjustment_identity()) {
128 float x_scale = decoded_image.scale_adjustment().width();
129 float y_scale = decoded_image.scale_adjustment().height();
130 adjusted_src =
131 SkRect::MakeXYWH(src->x() * x_scale, src->y() * y_scale,
132 src->width() * x_scale, src->height() * y_scale);
133 }
134 SkNWayCanvas::onDrawImageRect(decoded_image.image(), &adjusted_src, dst,
135 decoded_paint, constraint);
136 }
137
138 void onDrawImageNine(const SkImage* image,
139 const SkIRect& center,
140 const SkRect& dst,
141 const SkPaint* paint) override {
142 if (!image->isLazyGenerated()) {
143 SkNWayCanvas::onDrawImageNine(image, center, dst, paint);
144 return;
145 }
146
147 SkRect paint_bounds;
148 bool computed_paint_bounds = ComputePaintBounds(dst, paint, &paint_bounds);
149 if (computed_paint_bounds && !canvas_bounds_.intersects(paint_bounds))
150 return;
151
152 SkMatrix ctm = this->getTotalMatrix();
153 SkSize scale;
154 bool is_decomposable = ExtractScale(ctm, &scale);
155 ScopedDecodedImageLock scoped_lock(image_decode_controller_, image, scale,
156 is_decomposable, ctm.hasPerspective(),
157 paint);
158 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image();
159 const SkPaint* decoded_paint = scoped_lock.decoded_paint();
160
161 SkIRect adjusted_center = center;
162 if (!decoded_image.is_scale_adjustment_identity()) {
163 float x_scale = decoded_image.scale_adjustment().width();
164 float y_scale = decoded_image.scale_adjustment().height();
165 adjusted_center = SkIRect::MakeXYWH(
166 static_cast<int>(std::floor(center.x() * x_scale)),
167 static_cast<int>(std::floor(center.y() * y_scale)),
168 static_cast<int>(std::ceil(center.width() * x_scale)),
169 static_cast<int>(std::ceil(center.height() * y_scale)));
170 }
171 SkNWayCanvas::onDrawImageNine(decoded_image.image(), adjusted_center, dst,
172 decoded_paint);
173 }
174
175 private:
176 class ScopedDecodedImageLock {
177 public:
178 ScopedDecodedImageLock(ImageDecodeController* image_decode_controller,
179 const SkImage* image,
180 const SkSize& scale,
181 bool is_decomposable,
182 bool has_perspective,
183 const SkPaint* paint)
184 : image_decode_controller_(image_decode_controller),
185 paint_(paint),
186 draw_image_(image,
187 scale,
188 paint ? paint->getFilterQuality() : kNone_SkFilterQuality,
189 has_perspective,
190 is_decomposable),
191 decoded_draw_image_(
192 image_decode_controller_->GetDecodedImageForDraw(draw_image_)) {
193 DCHECK(image->isLazyGenerated());
194 if (paint) {
195 decoded_paint_ = *paint;
196 decoded_paint_.setFilterQuality(decoded_draw_image_.filter_quality());
197 }
198 }
199
200 ~ScopedDecodedImageLock() {
201 image_decode_controller_->DrawWithImageFinished(draw_image_,
202 decoded_draw_image_);
203 }
204
205 const DecodedDrawImage& decoded_image() const {
206 return decoded_draw_image_;
207 }
208 const SkPaint* decoded_paint() const {
209 return paint_ ? &decoded_paint_ : nullptr;
210 }
211
212 private:
213 ImageDecodeController* image_decode_controller_;
214 const SkPaint* paint_;
215 DrawImage draw_image_;
216 DecodedDrawImage decoded_draw_image_;
217 SkPaint decoded_paint_;
218 };
219
220 ImageDecodeController* image_decode_controller_;
221 const SkRect canvas_bounds_;
222 };
223
224 } // namespace
225
18 scoped_refptr<DisplayListRasterSource> 226 scoped_refptr<DisplayListRasterSource>
19 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 227 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
20 const DisplayListRecordingSource* other, 228 const DisplayListRecordingSource* other,
21 bool can_use_lcd_text) { 229 bool can_use_lcd_text) {
22 return make_scoped_refptr( 230 return make_scoped_refptr(
23 new DisplayListRasterSource(other, can_use_lcd_text)); 231 new DisplayListRasterSource(other, can_use_lcd_text));
24 } 232 }
25 233
26 DisplayListRasterSource::DisplayListRasterSource( 234 DisplayListRasterSource::DisplayListRasterSource(
27 const DisplayListRecordingSource* other, 235 const DisplayListRecordingSource* other,
28 bool can_use_lcd_text) 236 bool can_use_lcd_text)
29 : display_list_(other->display_list_), 237 : display_list_(other->display_list_),
30 painter_reported_memory_usage_(other->painter_reported_memory_usage_), 238 painter_reported_memory_usage_(other->painter_reported_memory_usage_),
31 background_color_(other->background_color_), 239 background_color_(other->background_color_),
32 requires_clear_(other->requires_clear_), 240 requires_clear_(other->requires_clear_),
33 can_use_lcd_text_(can_use_lcd_text), 241 can_use_lcd_text_(can_use_lcd_text),
34 is_solid_color_(other->is_solid_color_), 242 is_solid_color_(other->is_solid_color_),
35 solid_color_(other->solid_color_), 243 solid_color_(other->solid_color_),
36 recorded_viewport_(other->recorded_viewport_), 244 recorded_viewport_(other->recorded_viewport_),
37 size_(other->size_), 245 size_(other->size_),
38 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), 246 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_),
39 slow_down_raster_scale_factor_for_debug_( 247 slow_down_raster_scale_factor_for_debug_(
40 other->slow_down_raster_scale_factor_for_debug_), 248 other->slow_down_raster_scale_factor_for_debug_),
41 should_attempt_to_use_distance_field_text_(false) {} 249 should_attempt_to_use_distance_field_text_(false),
250 image_decode_controller_(nullptr) {}
42 251
43 DisplayListRasterSource::DisplayListRasterSource( 252 DisplayListRasterSource::DisplayListRasterSource(
44 const DisplayListRasterSource* other, 253 const DisplayListRasterSource* other,
45 bool can_use_lcd_text) 254 bool can_use_lcd_text)
46 : display_list_(other->display_list_), 255 : display_list_(other->display_list_),
47 painter_reported_memory_usage_(other->painter_reported_memory_usage_), 256 painter_reported_memory_usage_(other->painter_reported_memory_usage_),
48 background_color_(other->background_color_), 257 background_color_(other->background_color_),
49 requires_clear_(other->requires_clear_), 258 requires_clear_(other->requires_clear_),
50 can_use_lcd_text_(can_use_lcd_text), 259 can_use_lcd_text_(can_use_lcd_text),
51 is_solid_color_(other->is_solid_color_), 260 is_solid_color_(other->is_solid_color_),
52 solid_color_(other->solid_color_), 261 solid_color_(other->solid_color_),
53 recorded_viewport_(other->recorded_viewport_), 262 recorded_viewport_(other->recorded_viewport_),
54 size_(other->size_), 263 size_(other->size_),
55 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), 264 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_),
56 slow_down_raster_scale_factor_for_debug_( 265 slow_down_raster_scale_factor_for_debug_(
57 other->slow_down_raster_scale_factor_for_debug_), 266 other->slow_down_raster_scale_factor_for_debug_),
58 should_attempt_to_use_distance_field_text_( 267 should_attempt_to_use_distance_field_text_(
59 other->should_attempt_to_use_distance_field_text_) {} 268 other->should_attempt_to_use_distance_field_text_),
269 image_decode_controller_(other->image_decode_controller_) {}
60 270
61 DisplayListRasterSource::~DisplayListRasterSource() { 271 DisplayListRasterSource::~DisplayListRasterSource() {
62 } 272 }
63 273
64 void DisplayListRasterSource::PlaybackToSharedCanvas( 274 void DisplayListRasterSource::PlaybackToSharedCanvas(
65 SkCanvas* canvas, 275 SkCanvas* raster_canvas,
66 const gfx::Rect& canvas_rect, 276 const gfx::Rect& canvas_rect,
67 float contents_scale) const { 277 float contents_scale) const {
68 RasterCommon(canvas, NULL, canvas_rect, canvas_rect, contents_scale); 278 SkImageInfo info = raster_canvas->imageInfo();
279 ImageHijackCanvas canvas(info.width(), info.height(),
280 image_decode_controller_);
281 canvas.addCanvas(raster_canvas);
282
283 RasterCommon(&canvas, NULL, canvas_rect, canvas_rect, contents_scale);
69 } 284 }
70 285
71 void DisplayListRasterSource::RasterForAnalysis(skia::AnalysisCanvas* canvas, 286 void DisplayListRasterSource::RasterForAnalysis(skia::AnalysisCanvas* canvas,
72 const gfx::Rect& canvas_rect, 287 const gfx::Rect& canvas_rect,
73 float contents_scale) const { 288 float contents_scale) const {
74 RasterCommon(canvas, canvas, canvas_rect, canvas_rect, contents_scale); 289 RasterCommon(canvas, canvas, canvas_rect, canvas_rect, contents_scale);
75 } 290 }
76 291
77 void DisplayListRasterSource::PlaybackToCanvas( 292 void DisplayListRasterSource::PlaybackToCanvas(
78 SkCanvas* canvas, 293 SkCanvas* raster_canvas,
79 const gfx::Rect& canvas_bitmap_rect, 294 const gfx::Rect& canvas_bitmap_rect,
80 const gfx::Rect& canvas_playback_rect, 295 const gfx::Rect& canvas_playback_rect,
81 float contents_scale) const { 296 float contents_scale) const {
82 PrepareForPlaybackToCanvas(canvas, canvas_bitmap_rect, canvas_playback_rect, 297 PrepareForPlaybackToCanvas(raster_canvas, canvas_bitmap_rect,
83 contents_scale); 298 canvas_playback_rect, contents_scale);
84 RasterCommon(canvas, NULL, canvas_bitmap_rect, canvas_playback_rect, 299
300 SkImageInfo info = raster_canvas->imageInfo();
301 ImageHijackCanvas canvas(info.width(), info.height(),
302 image_decode_controller_);
303 canvas.addCanvas(raster_canvas);
304 RasterCommon(&canvas, NULL, canvas_bitmap_rect, canvas_playback_rect,
85 contents_scale); 305 contents_scale);
86 } 306 }
87 307
88 void DisplayListRasterSource::PrepareForPlaybackToCanvas( 308 void DisplayListRasterSource::PrepareForPlaybackToCanvas(
89 SkCanvas* canvas, 309 SkCanvas* canvas,
90 const gfx::Rect& canvas_bitmap_rect, 310 const gfx::Rect& canvas_bitmap_rect,
91 const gfx::Rect& canvas_playback_rect, 311 const gfx::Rect& canvas_playback_rect,
92 float contents_scale) const { 312 float contents_scale) const {
93 // TODO(hendrikw): See if we can split this up into separate functions. 313 // TODO(hendrikw): See if we can split this up into separate functions.
94 bool partial_update = canvas_bitmap_rect != canvas_playback_rect; 314 bool partial_update = canvas_bitmap_rect != canvas_playback_rect;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 return can_use_lcd_text_; 513 return can_use_lcd_text_;
294 } 514 }
295 515
296 scoped_refptr<DisplayListRasterSource> 516 scoped_refptr<DisplayListRasterSource>
297 DisplayListRasterSource::CreateCloneWithoutLCDText() const { 517 DisplayListRasterSource::CreateCloneWithoutLCDText() const {
298 bool can_use_lcd_text = false; 518 bool can_use_lcd_text = false;
299 return scoped_refptr<DisplayListRasterSource>( 519 return scoped_refptr<DisplayListRasterSource>(
300 new DisplayListRasterSource(this, can_use_lcd_text)); 520 new DisplayListRasterSource(this, can_use_lcd_text));
301 } 521 }
302 522
523 void DisplayListRasterSource::SetImageDecodeController(
524 ImageDecodeController* image_decode_controller) {
525 DCHECK(image_decode_controller);
526 // Note that although this function should only be called once, tests tend to
527 // call it several times using the same controller.
528 DCHECK(!image_decode_controller_ ||
529 image_decode_controller_ == image_decode_controller);
530 image_decode_controller_ = image_decode_controller;
531 }
532
303 } // namespace cc 533 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698