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 { | |
19 | |
20 SkRect MapRect(const SkMatrix& matrix, const SkRect& src) { | 18 SkRect MapRect(const SkMatrix& matrix, const SkRect& src) { |
21 SkRect dst; | 19 SkRect dst; |
22 matrix.mapRect(&dst, src); | 20 matrix.mapRect(&dst, src); |
23 return dst; | 21 return dst; |
24 } | 22 } |
25 | 23 |
26 SkSize ExtractScale(const SkMatrix& matrix) { | 24 bool ExtractScale(const SkMatrix& matrix, SkSize* scale) { |
27 SkSize scale = SkSize::Make(matrix.getScaleX(), matrix.getScaleY()); | 25 *scale = SkSize::Make(matrix.getScaleX(), matrix.getScaleY()); |
28 if (matrix.getType() & SkMatrix::kAffine_Mask) { | 26 if (matrix.getType() & SkMatrix::kAffine_Mask) { |
29 if (!matrix.decomposeScale(&scale)) | 27 if (!matrix.decomposeScale(scale)) { |
30 scale.set(1, 1); | 28 scale->set(1, 1); |
| 29 return false; |
| 30 } |
31 } | 31 } |
32 return scale; | 32 return true; |
33 } | 33 } |
34 | 34 |
| 35 namespace { |
| 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) |
43 : SkNWayCanvas(width, height), | 45 : SkNWayCanvas(width, height), |
44 image_set_(image_set), | 46 image_set_(image_set), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 const SkRect& dst, | 87 const SkRect& dst, |
86 const SkPaint* paint) override { | 88 const SkPaint* paint) override { |
87 AddImage(image, dst, this->getTotalMatrix(), paint); | 89 AddImage(image, dst, this->getTotalMatrix(), paint); |
88 } | 90 } |
89 | 91 |
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 (!image->isLazyGenerated()) |
96 SkFilterQuality filter_quality = kNone_SkFilterQuality; | 98 return; |
97 if (paint) { | 99 |
98 filter_quality = paint->getFilterQuality(); | 100 SkRect paint_rect = rect; |
| 101 if (paint) { |
| 102 if (paint->canComputeFastBounds()) { |
| 103 paint_rect = paint->computeFastBounds(rect, &paint_rect); |
| 104 } else { |
| 105 // TODO(vmpstr): UMA this case. |
| 106 paint_rect = canvas_bounds_; |
99 } | 107 } |
100 image_set_->push_back( | |
101 std::make_pair(DrawImage(image, ExtractScale(matrix), filter_quality), | |
102 gfx::SkRectToRectF(rect))); | |
103 } | 108 } |
| 109 |
| 110 if (!rect.intersects(canvas_bounds_)) |
| 111 return; |
| 112 |
| 113 SkFilterQuality filter_quality = kNone_SkFilterQuality; |
| 114 if (paint) { |
| 115 filter_quality = paint->getFilterQuality(); |
| 116 } |
| 117 |
| 118 SkSize scale; |
| 119 bool is_decomposable = ExtractScale(matrix, &scale); |
| 120 image_set_->push_back( |
| 121 std::make_pair(DrawImage(image, scale, filter_quality, |
| 122 matrix.hasPerspective(), is_decomposable), |
| 123 gfx::SkRectToRectF(rect))); |
104 } | 124 } |
105 | 125 |
106 std::vector<std::pair<DrawImage, gfx::RectF>>* image_set_; | 126 std::vector<std::pair<DrawImage, gfx::RectF>>* image_set_; |
107 const SkRect canvas_bounds_; | 127 const SkRect canvas_bounds_; |
108 }; | 128 }; |
109 | 129 |
110 } // namespace | 130 } // namespace |
111 | 131 |
112 DiscardableImageMap::DiscardableImageMap() {} | 132 DiscardableImageMap::DiscardableImageMap() {} |
113 | 133 |
(...skipping 25 matching lines...) Expand all Loading... |
139 DiscardableImageMap* image_map, | 159 DiscardableImageMap* image_map, |
140 const gfx::Size& bounds) | 160 const gfx::Size& bounds) |
141 : image_map_(image_map), | 161 : image_map_(image_map), |
142 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} | 162 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} |
143 | 163 |
144 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { | 164 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { |
145 image_map_->EndGeneratingMetadata(); | 165 image_map_->EndGeneratingMetadata(); |
146 } | 166 } |
147 | 167 |
148 } // namespace cc | 168 } // namespace cc |
OLD | NEW |