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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
11 #include "cc/playback/display_item_list.h" | 11 #include "cc/playback/display_item_list.h" |
12 #include "third_party/skia/include/utils/SkNWayCanvas.h" | 12 #include "third_party/skia/include/utils/SkNWayCanvas.h" |
13 #include "ui/gfx/geometry/rect_conversions.h" | 13 #include "ui/gfx/geometry/rect_conversions.h" |
14 #include "ui/gfx/skia_util.h" | 14 #include "ui/gfx/skia_util.h" |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 SkRect MapRect(const SkMatrix& matrix, const SkRect& src) { | 20 SkRect MapRect(const SkMatrix& matrix, const SkRect& src) { |
21 SkRect dst; | 21 SkRect dst; |
22 matrix.mapRect(&dst, src); | 22 matrix.mapRect(&dst, src); |
23 return dst; | 23 return dst; |
24 } | 24 } |
25 | 25 |
26 SkSize ExtractScale(const SkMatrix& matrix) { | 26 bool ExtractScale(const SkMatrix& matrix, SkSize* scale) { |
27 SkSize scale = SkSize::Make(matrix.getScaleX(), matrix.getScaleY()); | 27 *scale = SkSize::Make(matrix.getScaleX(), matrix.getScaleY()); |
28 if (matrix.getType() & SkMatrix::kAffine_Mask) { | 28 if (matrix.getType() & SkMatrix::kAffine_Mask) { |
29 if (!matrix.decomposeScale(&scale)) | 29 if (!matrix.decomposeScale(scale)) { |
30 scale.set(1, 1); | 30 scale->set(1, 1); |
| 31 return false; |
| 32 } |
31 } | 33 } |
32 return scale; | 34 return true; |
33 } | 35 } |
34 | 36 |
35 // We're using an NWay canvas with no added canvases, so in effect | 37 // We're using an NWay canvas with no added canvases, so in effect |
36 // non-overridden functions are no-ops. | 38 // non-overridden functions are no-ops. |
37 class DiscardableImagesMetadataCanvas : public SkNWayCanvas { | 39 class DiscardableImagesMetadataCanvas : public SkNWayCanvas { |
38 public: | 40 public: |
39 DiscardableImagesMetadataCanvas( | 41 DiscardableImagesMetadataCanvas( |
40 int width, | 42 int width, |
41 int height, | 43 int height, |
42 std::vector<std::pair<DrawImage, gfx::RectF>>* image_set) | 44 std::vector<std::pair<DrawImage, gfx::RectF>>* image_set) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 private: | 92 private: |
91 void AddImage(const SkImage* image, | 93 void AddImage(const SkImage* image, |
92 const SkRect& rect, | 94 const SkRect& rect, |
93 const SkMatrix& matrix, | 95 const SkMatrix& matrix, |
94 const SkPaint* paint) { | 96 const SkPaint* paint) { |
95 if (rect.intersects(canvas_bounds_) && image->isLazyGenerated()) { | 97 if (rect.intersects(canvas_bounds_) && image->isLazyGenerated()) { |
96 SkFilterQuality filter_quality = kNone_SkFilterQuality; | 98 SkFilterQuality filter_quality = kNone_SkFilterQuality; |
97 if (paint) { | 99 if (paint) { |
98 filter_quality = paint->getFilterQuality(); | 100 filter_quality = paint->getFilterQuality(); |
99 } | 101 } |
| 102 SkSize scale; |
| 103 bool is_decomposable = ExtractScale(matrix, &scale); |
100 image_set_->push_back( | 104 image_set_->push_back( |
101 std::make_pair(DrawImage(image, ExtractScale(matrix), filter_quality), | 105 std::make_pair(DrawImage(image, scale, filter_quality, |
| 106 matrix.hasPerspective(), is_decomposable), |
102 gfx::SkRectToRectF(rect))); | 107 gfx::SkRectToRectF(rect))); |
103 } | 108 } |
104 } | 109 } |
105 | 110 |
106 std::vector<std::pair<DrawImage, gfx::RectF>>* image_set_; | 111 std::vector<std::pair<DrawImage, gfx::RectF>>* image_set_; |
107 const SkRect canvas_bounds_; | 112 const SkRect canvas_bounds_; |
108 }; | 113 }; |
109 | 114 |
110 } // namespace | 115 } // namespace |
111 | 116 |
(...skipping 27 matching lines...) Expand all Loading... |
139 DiscardableImageMap* image_map, | 144 DiscardableImageMap* image_map, |
140 const gfx::Size& bounds) | 145 const gfx::Size& bounds) |
141 : image_map_(image_map), | 146 : image_map_(image_map), |
142 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} | 147 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} |
143 | 148 |
144 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { | 149 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { |
145 image_map_->EndGeneratingMetadata(); | 150 image_map_->EndGeneratingMetadata(); |
146 } | 151 } |
147 | 152 |
148 } // namespace cc | 153 } // namespace cc |
OLD | NEW |