Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/containers/adapters.h" | 12 #include "base/containers/adapters.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
| 15 #include "cc/playback/display_item_list.h" | 15 #include "cc/playback/display_item_list.h" |
| 16 #include "third_party/skia/include/core/SkPath.h" | |
| 16 #include "third_party/skia/include/utils/SkNWayCanvas.h" | 17 #include "third_party/skia/include/utils/SkNWayCanvas.h" |
| 17 #include "ui/gfx/geometry/rect_conversions.h" | 18 #include "ui/gfx/geometry/rect_conversions.h" |
| 18 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
| 19 | 20 |
| 20 namespace cc { | 21 namespace cc { |
| 21 | 22 |
| 22 SkRect MapRect(const SkMatrix& matrix, const SkRect& src) { | 23 SkRect MapRect(const SkMatrix& matrix, const SkRect& src) { |
| 23 SkRect dst; | 24 SkRect dst; |
| 24 matrix.mapRect(&dst, src); | 25 matrix.mapRect(&dst, src); |
| 25 return dst; | 26 return dst; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 const SkPaint* paint, | 94 const SkPaint* paint, |
| 94 SrcRectConstraint) override { | 95 SrcRectConstraint) override { |
| 95 const SkMatrix& ctm = getTotalMatrix(); | 96 const SkMatrix& ctm = getTotalMatrix(); |
| 96 SkRect src_storage; | 97 SkRect src_storage; |
| 97 if (!src) { | 98 if (!src) { |
| 98 src_storage = SkRect::MakeIWH(image->width(), image->height()); | 99 src_storage = SkRect::MakeIWH(image->width(), image->height()); |
| 99 src = &src_storage; | 100 src = &src_storage; |
| 100 } | 101 } |
| 101 SkMatrix matrix; | 102 SkMatrix matrix; |
| 102 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); | 103 matrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); |
| 103 matrix.postConcat(ctm); | 104 matrix.preConcat(ctm); |
| 104 AddImage(sk_ref_sp(image), *src, MapRect(ctm, dst), matrix, paint); | 105 AddImage(sk_ref_sp(image), *src, MapRect(ctm, dst), matrix, paint); |
| 105 } | 106 } |
| 106 | 107 |
| 107 void onDrawImageNine(const SkImage* image, | 108 void onDrawImageNine(const SkImage* image, |
| 108 const SkIRect& center, | 109 const SkIRect& center, |
| 109 const SkRect& dst, | 110 const SkRect& dst, |
| 110 const SkPaint* paint) override { | 111 const SkPaint* paint) override { |
| 111 // No cc embedder issues image nine calls. | 112 // No cc embedder issues image nine calls. |
| 112 NOTREACHED(); | 113 NOTREACHED(); |
| 113 } | 114 } |
| 114 | 115 |
| 116 void onDrawRect(const SkRect& r, const SkPaint& paint) override { | |
| 117 AddPaintImage(r, paint); | |
| 118 } | |
| 119 | |
| 120 void onDrawPath(const SkPath& path, const SkPaint& paint) override { | |
| 121 AddPaintImage(path.getBounds(), paint); | |
| 122 } | |
| 123 | |
| 124 void onDrawOval(const SkRect& r, const SkPaint& paint) override { | |
| 125 AddPaintImage(r, paint); | |
| 126 } | |
| 127 | |
| 128 void onDrawArc(const SkRect& r, | |
| 129 SkScalar start_angle, | |
| 130 SkScalar sweep_angle, | |
| 131 bool use_center, | |
| 132 const SkPaint& paint) override { | |
| 133 AddPaintImage(r, paint); | |
| 134 } | |
| 135 | |
| 136 void onDrawRRect(const SkRRect& rr, const SkPaint& paint) override { | |
| 137 AddPaintImage(rr.rect(), paint); | |
| 138 } | |
| 139 | |
| 115 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override { | 140 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override { |
| 116 saved_paints_.push_back(*rec.fPaint); | 141 saved_paints_.push_back(*rec.fPaint); |
| 117 return SkNWayCanvas::getSaveLayerStrategy(rec); | 142 return SkNWayCanvas::getSaveLayerStrategy(rec); |
| 118 } | 143 } |
| 119 | 144 |
| 120 void willSave() override { | 145 void willSave() override { |
| 121 saved_paints_.push_back(SkPaint()); | 146 saved_paints_.push_back(SkPaint()); |
| 122 return SkNWayCanvas::willSave(); | 147 return SkNWayCanvas::willSave(); |
| 123 } | 148 } |
| 124 | 149 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 filter_quality = paint->getFilterQuality(); | 196 filter_quality = paint->getFilterQuality(); |
| 172 } | 197 } |
| 173 | 198 |
| 174 SkIRect src_irect; | 199 SkIRect src_irect; |
| 175 src_rect.roundOut(&src_irect); | 200 src_rect.roundOut(&src_irect); |
| 176 image_set_->push_back(std::make_pair( | 201 image_set_->push_back(std::make_pair( |
| 177 DrawImage(std::move(image), src_irect, filter_quality, matrix), | 202 DrawImage(std::move(image), src_irect, filter_quality, matrix), |
| 178 SafeClampPaintRectToSize(paint_rect, canvas_size_))); | 203 SafeClampPaintRectToSize(paint_rect, canvas_size_))); |
| 179 } | 204 } |
| 180 | 205 |
| 206 // Currently this function only handles extracting images from SkImageShaders | |
| 207 // embedded in SkPaints. Other embedded image cases, such as SkPictures, | |
| 208 // are not yet handled. | |
| 209 void AddPaintImage(const SkRect& rect, const SkPaint& paint) { | |
| 210 SkShader* shader = paint.getShader(); | |
| 211 if (shader) { | |
| 212 SkMatrix matrix; | |
| 213 SkShader::TileMode xy[2]; | |
| 214 SkImage* image = shader->isAImage(&matrix, xy); | |
| 215 if (image) { | |
| 216 const SkMatrix& ctm = getTotalMatrix(); | |
| 217 matrix.postConcat(ctm); | |
| 218 // TODO(ericrk): Handle cases where we only need a sub-rect from the | |
|
vmpstr
2016/12/06 22:43:36
Do you wanna file a bug for this and reference it
ericrk
2016/12/06 23:08:51
Will add in a follow-up CL.
| |
| 219 // image. | |
| 220 AddImage(sk_ref_sp(image), SkRect::MakeFromIRect(image->bounds()), | |
| 221 MapRect(ctm, rect), matrix, &paint); | |
| 222 } | |
| 223 } | |
| 224 } | |
| 225 | |
| 181 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set_; | 226 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set_; |
| 182 const SkRect canvas_bounds_; | 227 const SkRect canvas_bounds_; |
| 183 const gfx::Size canvas_size_; | 228 const gfx::Size canvas_size_; |
| 184 std::vector<SkPaint> saved_paints_; | 229 std::vector<SkPaint> saved_paints_; |
| 185 }; | 230 }; |
| 186 | 231 |
| 187 } // namespace | 232 } // namespace |
| 188 | 233 |
| 189 DiscardableImageMap::DiscardableImageMap() {} | 234 DiscardableImageMap::DiscardableImageMap() {} |
| 190 | 235 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 218 DiscardableImageMap* image_map, | 263 DiscardableImageMap* image_map, |
| 219 const gfx::Size& bounds) | 264 const gfx::Size& bounds) |
| 220 : image_map_(image_map), | 265 : image_map_(image_map), |
| 221 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} | 266 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} |
| 222 | 267 |
| 223 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { | 268 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { |
| 224 image_map_->EndGeneratingMetadata(); | 269 image_map_->EndGeneratingMetadata(); |
| 225 } | 270 } |
| 226 | 271 |
| 227 } // namespace cc | 272 } // namespace cc |
| OLD | NEW |