| 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/display_list_raster_source.h" | 5 #include "cc/playback/display_list_raster_source.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/containers/adapters.h" | |
| 10 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 11 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/trace_event/memory_dump_manager.h" | 11 #include "base/trace_event/memory_dump_manager.h" |
| 13 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 14 #include "cc/base/region.h" | 13 #include "cc/base/region.h" |
| 15 #include "cc/debug/debug_colors.h" | 14 #include "cc/debug/debug_colors.h" |
| 16 #include "cc/playback/discardable_image_map.h" | |
| 17 #include "cc/playback/display_item_list.h" | 15 #include "cc/playback/display_item_list.h" |
| 18 #include "cc/tiles/image_decode_controller.h" | 16 #include "cc/playback/image_hijack_canvas.h" |
| 19 #include "skia/ext/analysis_canvas.h" | 17 #include "skia/ext/analysis_canvas.h" |
| 20 #include "third_party/skia/include/core/SkCanvas.h" | 18 #include "third_party/skia/include/core/SkCanvas.h" |
| 21 #include "third_party/skia/include/core/SkPictureRecorder.h" | 19 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 22 #include "third_party/skia/include/core/SkTLazy.h" | 20 #include "third_party/skia/include/core/SkTLazy.h" |
| 23 #include "third_party/skia/include/utils/SkNWayCanvas.h" | |
| 24 #include "ui/gfx/geometry/rect_conversions.h" | 21 #include "ui/gfx/geometry/rect_conversions.h" |
| 25 | 22 |
| 26 namespace cc { | 23 namespace cc { |
| 27 | 24 |
| 28 namespace { | |
| 29 | |
| 30 SkIRect RoundOutRect(const SkRect& rect) { | |
| 31 SkIRect result; | |
| 32 rect.roundOut(&result); | |
| 33 return result; | |
| 34 } | |
| 35 | |
| 36 class ImageHijackCanvas : public SkNWayCanvas { | |
| 37 public: | |
| 38 ImageHijackCanvas(int width, | |
| 39 int height, | |
| 40 ImageDecodeController* image_decode_controller) | |
| 41 : SkNWayCanvas(width, height), | |
| 42 image_decode_controller_(image_decode_controller) {} | |
| 43 | |
| 44 protected: | |
| 45 // Ensure that pictures are unpacked by this canvas, instead of being | |
| 46 // forwarded to the raster canvas. | |
| 47 void onDrawPicture(const SkPicture* picture, | |
| 48 const SkMatrix* matrix, | |
| 49 const SkPaint* paint) override { | |
| 50 SkCanvas::onDrawPicture(picture, matrix, paint); | |
| 51 } | |
| 52 | |
| 53 void onDrawImage(const SkImage* image, | |
| 54 SkScalar x, | |
| 55 SkScalar y, | |
| 56 const SkPaint* paint) override { | |
| 57 if (!image->isLazyGenerated()) { | |
| 58 SkNWayCanvas::onDrawImage(image, x, y, paint); | |
| 59 return; | |
| 60 } | |
| 61 | |
| 62 SkMatrix ctm = getTotalMatrix(); | |
| 63 | |
| 64 SkSize scale; | |
| 65 bool is_decomposable = ExtractScale(ctm, &scale); | |
| 66 ScopedDecodedImageLock scoped_lock( | |
| 67 image_decode_controller_, image, | |
| 68 SkRect::MakeIWH(image->width(), image->height()), scale, | |
| 69 is_decomposable, ctm.hasPerspective(), paint); | |
| 70 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); | |
| 71 if (!decoded_image.image()) | |
| 72 return; | |
| 73 | |
| 74 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().width())); | |
| 75 DCHECK_EQ(0, static_cast<int>(decoded_image.src_rect_offset().height())); | |
| 76 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); | |
| 77 | |
| 78 bool need_scale = !decoded_image.is_scale_adjustment_identity(); | |
| 79 if (need_scale) { | |
| 80 SkNWayCanvas::save(); | |
| 81 SkNWayCanvas::scale(1.f / (decoded_image.scale_adjustment().width()), | |
| 82 1.f / (decoded_image.scale_adjustment().height())); | |
| 83 } | |
| 84 SkNWayCanvas::onDrawImage(decoded_image.image(), x, y, decoded_paint); | |
| 85 if (need_scale) | |
| 86 SkNWayCanvas::restore(); | |
| 87 } | |
| 88 | |
| 89 void onDrawImageRect(const SkImage* image, | |
| 90 const SkRect* src, | |
| 91 const SkRect& dst, | |
| 92 const SkPaint* paint, | |
| 93 SrcRectConstraint constraint) override { | |
| 94 if (!image->isLazyGenerated()) { | |
| 95 SkNWayCanvas::onDrawImageRect(image, src, dst, paint, constraint); | |
| 96 return; | |
| 97 } | |
| 98 | |
| 99 SkRect src_storage; | |
| 100 if (!src) { | |
| 101 src_storage = SkRect::MakeIWH(image->width(), image->height()); | |
| 102 src = &src_storage; | |
| 103 } | |
| 104 SkMatrix matrix; | |
| 105 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); | |
| 106 matrix.postConcat(getTotalMatrix()); | |
| 107 | |
| 108 SkSize scale; | |
| 109 bool is_decomposable = ExtractScale(matrix, &scale); | |
| 110 ScopedDecodedImageLock scoped_lock(image_decode_controller_, image, *src, | |
| 111 scale, is_decomposable, | |
| 112 matrix.hasPerspective(), paint); | |
| 113 const DecodedDrawImage& decoded_image = scoped_lock.decoded_image(); | |
| 114 if (!decoded_image.image()) | |
| 115 return; | |
| 116 | |
| 117 const SkPaint* decoded_paint = scoped_lock.decoded_paint(); | |
| 118 | |
| 119 SkRect adjusted_src = | |
| 120 src->makeOffset(decoded_image.src_rect_offset().width(), | |
| 121 decoded_image.src_rect_offset().height()); | |
| 122 if (!decoded_image.is_scale_adjustment_identity()) { | |
| 123 float x_scale = decoded_image.scale_adjustment().width(); | |
| 124 float y_scale = decoded_image.scale_adjustment().height(); | |
| 125 adjusted_src = SkRect::MakeXYWH( | |
| 126 adjusted_src.x() * x_scale, adjusted_src.y() * y_scale, | |
| 127 adjusted_src.width() * x_scale, adjusted_src.height() * y_scale); | |
| 128 } | |
| 129 SkNWayCanvas::onDrawImageRect(decoded_image.image(), &adjusted_src, dst, | |
| 130 decoded_paint, constraint); | |
| 131 } | |
| 132 | |
| 133 void onDrawImageNine(const SkImage* image, | |
| 134 const SkIRect& center, | |
| 135 const SkRect& dst, | |
| 136 const SkPaint* paint) override { | |
| 137 // No cc embedder issues image nine calls. | |
| 138 NOTREACHED(); | |
| 139 } | |
| 140 | |
| 141 private: | |
| 142 class ScopedDecodedImageLock { | |
| 143 public: | |
| 144 ScopedDecodedImageLock(ImageDecodeController* image_decode_controller, | |
| 145 const SkImage* image, | |
| 146 const SkRect& src_rect, | |
| 147 const SkSize& scale, | |
| 148 bool is_decomposable, | |
| 149 bool has_perspective, | |
| 150 const SkPaint* paint) | |
| 151 : image_decode_controller_(image_decode_controller), | |
| 152 draw_image_(image, | |
| 153 RoundOutRect(src_rect), | |
| 154 scale, | |
| 155 paint ? paint->getFilterQuality() : kNone_SkFilterQuality, | |
| 156 has_perspective, | |
| 157 is_decomposable), | |
| 158 decoded_draw_image_( | |
| 159 image_decode_controller_->GetDecodedImageForDraw(draw_image_)) { | |
| 160 DCHECK(image->isLazyGenerated()); | |
| 161 if (paint) | |
| 162 decoded_paint_.set(*paint)->setFilterQuality( | |
| 163 decoded_draw_image_.filter_quality()); | |
| 164 } | |
| 165 | |
| 166 ~ScopedDecodedImageLock() { | |
| 167 image_decode_controller_->DrawWithImageFinished(draw_image_, | |
| 168 decoded_draw_image_); | |
| 169 } | |
| 170 | |
| 171 const DecodedDrawImage& decoded_image() const { | |
| 172 return decoded_draw_image_; | |
| 173 } | |
| 174 const SkPaint* decoded_paint() const { | |
| 175 return decoded_paint_.getMaybeNull(); | |
| 176 } | |
| 177 | |
| 178 private: | |
| 179 ImageDecodeController* image_decode_controller_; | |
| 180 DrawImage draw_image_; | |
| 181 DecodedDrawImage decoded_draw_image_; | |
| 182 // TODO(fmalita): use base::Optional when it becomes available | |
| 183 SkTLazy<SkPaint> decoded_paint_; | |
| 184 }; | |
| 185 | |
| 186 ImageDecodeController* image_decode_controller_; | |
| 187 }; | |
| 188 | |
| 189 } // namespace | |
| 190 | |
| 191 scoped_refptr<DisplayListRasterSource> | 25 scoped_refptr<DisplayListRasterSource> |
| 192 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 26 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
| 193 const DisplayListRecordingSource* other, | 27 const DisplayListRecordingSource* other, |
| 194 bool can_use_lcd_text) { | 28 bool can_use_lcd_text) { |
| 195 return make_scoped_refptr( | 29 return make_scoped_refptr( |
| 196 new DisplayListRasterSource(other, can_use_lcd_text)); | 30 new DisplayListRasterSource(other, can_use_lcd_text)); |
| 197 } | 31 } |
| 198 | 32 |
| 199 DisplayListRasterSource::DisplayListRasterSource( | 33 DisplayListRasterSource::DisplayListRasterSource( |
| 200 const DisplayListRecordingSource* other, | 34 const DisplayListRecordingSource* other, |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 base::trace_event::MemoryAllocatorDump* dump = | 375 base::trace_event::MemoryAllocatorDump* dump = |
| 542 pmd->CreateAllocatorDump(dump_name); | 376 pmd->CreateAllocatorDump(dump_name); |
| 543 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 377 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 544 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 378 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 545 memory_usage); | 379 memory_usage); |
| 546 } | 380 } |
| 547 return true; | 381 return true; |
| 548 } | 382 } |
| 549 | 383 |
| 550 } // namespace cc | 384 } // namespace cc |
| OLD | NEW |