| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/discardable_image_map.h" | 5 #include "cc/playback/discardable_image_map.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 const SkPaint* paint) override { | 46 const SkPaint* paint) override { |
| 47 SkCanvas::onDrawPicture(picture, matrix, paint); | 47 SkCanvas::onDrawPicture(picture, matrix, paint); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void onDrawImage(const SkImage* image, | 50 void onDrawImage(const SkImage* image, |
| 51 SkScalar x, | 51 SkScalar x, |
| 52 SkScalar y, | 52 SkScalar y, |
| 53 const SkPaint* paint) override { | 53 const SkPaint* paint) override { |
| 54 const SkMatrix& ctm = getTotalMatrix(); | 54 const SkMatrix& ctm = getTotalMatrix(); |
| 55 AddImage( | 55 AddImage( |
| 56 image, SkRect::MakeIWH(image->width(), image->height()), | 56 sk_ref_sp(image), SkRect::MakeIWH(image->width(), image->height()), |
| 57 MapRect(ctm, SkRect::MakeXYWH(x, y, image->width(), image->height())), | 57 MapRect(ctm, SkRect::MakeXYWH(x, y, image->width(), image->height())), |
| 58 ctm, paint); | 58 ctm, paint); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void onDrawImageRect(const SkImage* image, | 61 void onDrawImageRect(const SkImage* image, |
| 62 const SkRect* src, | 62 const SkRect* src, |
| 63 const SkRect& dst, | 63 const SkRect& dst, |
| 64 const SkPaint* paint, | 64 const SkPaint* paint, |
| 65 SrcRectConstraint) override { | 65 SrcRectConstraint) override { |
| 66 const SkMatrix& ctm = getTotalMatrix(); | 66 const SkMatrix& ctm = getTotalMatrix(); |
| 67 SkRect src_storage; | 67 SkRect src_storage; |
| 68 if (!src) { | 68 if (!src) { |
| 69 src_storage = SkRect::MakeIWH(image->width(), image->height()); | 69 src_storage = SkRect::MakeIWH(image->width(), image->height()); |
| 70 src = &src_storage; | 70 src = &src_storage; |
| 71 } | 71 } |
| 72 SkMatrix matrix; | 72 SkMatrix matrix; |
| 73 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); | 73 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); |
| 74 matrix.postConcat(ctm); | 74 matrix.postConcat(ctm); |
| 75 AddImage(image, *src, MapRect(ctm, dst), matrix, paint); | 75 AddImage(sk_ref_sp(image), *src, MapRect(ctm, dst), matrix, paint); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void onDrawImageNine(const SkImage* image, | 78 void onDrawImageNine(const SkImage* image, |
| 79 const SkIRect& center, | 79 const SkIRect& center, |
| 80 const SkRect& dst, | 80 const SkRect& dst, |
| 81 const SkPaint* paint) override { | 81 const SkPaint* paint) override { |
| 82 // No cc embedder issues image nine calls. | 82 // No cc embedder issues image nine calls. |
| 83 NOTREACHED(); | 83 NOTREACHED(); |
| 84 } | 84 } |
| 85 | 85 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 for (const auto& paint : base::Reversed(saved_paints_)) { | 114 for (const auto& paint : base::Reversed(saved_paints_)) { |
| 115 if (!paint.canComputeFastBounds()) | 115 if (!paint.canComputeFastBounds()) |
| 116 return false; | 116 return false; |
| 117 *paint_bounds = paint.computeFastBounds(*paint_bounds, paint_bounds); | 117 *paint_bounds = paint.computeFastBounds(*paint_bounds, paint_bounds); |
| 118 } | 118 } |
| 119 return true; | 119 return true; |
| 120 } | 120 } |
| 121 | 121 |
| 122 void AddImage(const SkImage* image, | 122 void AddImage(sk_sp<const SkImage> image, |
| 123 const SkRect& src_rect, | 123 const SkRect& src_rect, |
| 124 const SkRect& rect, | 124 const SkRect& rect, |
| 125 const SkMatrix& matrix, | 125 const SkMatrix& matrix, |
| 126 const SkPaint* paint) { | 126 const SkPaint* paint) { |
| 127 if (!image->isLazyGenerated()) | 127 if (!image->isLazyGenerated()) |
| 128 return; | 128 return; |
| 129 | 129 |
| 130 SkRect paint_rect; | 130 SkRect paint_rect; |
| 131 bool computed_paint_bounds = ComputePaintBounds(rect, paint, &paint_rect); | 131 bool computed_paint_bounds = ComputePaintBounds(rect, paint, &paint_rect); |
| 132 if (!computed_paint_bounds) { | 132 if (!computed_paint_bounds) { |
| 133 // TODO(vmpstr): UMA this case. | 133 // TODO(vmpstr): UMA this case. |
| 134 paint_rect = canvas_bounds_; | 134 paint_rect = canvas_bounds_; |
| 135 } | 135 } |
| 136 | 136 |
| 137 if (!paint_rect.intersects(canvas_bounds_)) | 137 if (!paint_rect.intersects(canvas_bounds_)) |
| 138 return; | 138 return; |
| 139 | 139 |
| 140 SkFilterQuality filter_quality = kNone_SkFilterQuality; | 140 SkFilterQuality filter_quality = kNone_SkFilterQuality; |
| 141 if (paint) { | 141 if (paint) { |
| 142 filter_quality = paint->getFilterQuality(); | 142 filter_quality = paint->getFilterQuality(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 SkIRect src_irect; | 145 SkIRect src_irect; |
| 146 src_rect.roundOut(&src_irect); | 146 src_rect.roundOut(&src_irect); |
| 147 image_set_->push_back( | 147 image_set_->push_back(std::make_pair( |
| 148 std::make_pair(DrawImage(image, src_irect, filter_quality, matrix), | 148 DrawImage(std::move(image), src_irect, filter_quality, matrix), |
| 149 gfx::ToEnclosingRect(gfx::SkRectToRectF(paint_rect)))); | 149 gfx::ToEnclosingRect(gfx::SkRectToRectF(paint_rect)))); |
| 150 } | 150 } |
| 151 | 151 |
| 152 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set_; | 152 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set_; |
| 153 const SkRect canvas_bounds_; | 153 const SkRect canvas_bounds_; |
| 154 std::vector<SkPaint> saved_paints_; | 154 std::vector<SkPaint> saved_paints_; |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 } // namespace | 157 } // namespace |
| 158 | 158 |
| 159 DiscardableImageMap::DiscardableImageMap() {} | 159 DiscardableImageMap::DiscardableImageMap() {} |
| 160 | 160 |
| 161 DiscardableImageMap::~DiscardableImageMap() {} | 161 DiscardableImageMap::~DiscardableImageMap() {} |
| 162 | 162 |
| 163 skia::RefPtr<SkCanvas> DiscardableImageMap::BeginGeneratingMetadata( | 163 sk_sp<SkCanvas> DiscardableImageMap::BeginGeneratingMetadata( |
| 164 const gfx::Size& bounds) { | 164 const gfx::Size& bounds) { |
| 165 DCHECK(all_images_.empty()); | 165 DCHECK(all_images_.empty()); |
| 166 return skia::AdoptRef(new DiscardableImagesMetadataCanvas( | 166 return sk_make_sp<DiscardableImagesMetadataCanvas>( |
| 167 bounds.width(), bounds.height(), &all_images_)); | 167 bounds.width(), bounds.height(), &all_images_); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void DiscardableImageMap::EndGeneratingMetadata() { | 170 void DiscardableImageMap::EndGeneratingMetadata() { |
| 171 images_rtree_.Build(all_images_, | 171 images_rtree_.Build(all_images_, |
| 172 [](const std::pair<DrawImage, gfx::Rect>& image) { | 172 [](const std::pair<DrawImage, gfx::Rect>& image) { |
| 173 return image.second; | 173 return image.second; |
| 174 }); | 174 }); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void DiscardableImageMap::GetDiscardableImagesInRect( | 177 void DiscardableImageMap::GetDiscardableImagesInRect( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 188 DiscardableImageMap* image_map, | 188 DiscardableImageMap* image_map, |
| 189 const gfx::Size& bounds) | 189 const gfx::Size& bounds) |
| 190 : image_map_(image_map), | 190 : image_map_(image_map), |
| 191 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} | 191 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} |
| 192 | 192 |
| 193 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { | 193 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { |
| 194 image_map_->EndGeneratingMetadata(); | 194 image_map_->EndGeneratingMetadata(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 } // namespace cc | 197 } // namespace cc |
| OLD | NEW |