OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/paint/discardable_image_store.h" | 5 #include "cc/paint/discardable_image_store.h" |
6 | 6 |
7 #include "base/containers/adapters.h" | 7 #include "base/containers/adapters.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "cc/paint/display_item_list.h" | 9 #include "cc/paint/display_item_list.h" |
10 #include "third_party/skia/include/utils/SkNoDrawCanvas.h" | 10 #include "third_party/skia/include/utils/SkNoDrawCanvas.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 std::vector<SkPaint> saved_paints_; | 68 std::vector<SkPaint> saved_paints_; |
69 }; | 69 }; |
70 | 70 |
71 DiscardableImageStore::DiscardableImageStore( | 71 DiscardableImageStore::DiscardableImageStore( |
72 int width, | 72 int width, |
73 int height, | 73 int height, |
74 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set, | 74 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set, |
75 base::flat_map<ImageId, gfx::Rect>* image_id_to_rect) | 75 base::flat_map<ImageId, gfx::Rect>* image_id_to_rect) |
76 : canvas_(base::MakeUnique<PaintTrackingCanvas>(width, height)), | 76 : canvas_(base::MakeUnique<PaintTrackingCanvas>(width, height)), |
77 image_set_(image_set), | 77 image_set_(image_set), |
78 image_id_to_rect_(image_id_to_rect) {} | 78 image_id_to_rect_(image_id_to_rect), |
| 79 unknown_stable_id_(PaintImage::GetNextId()) {} |
79 | 80 |
80 DiscardableImageStore::~DiscardableImageStore() = default; | 81 DiscardableImageStore::~DiscardableImageStore() = default; |
81 | 82 |
82 SkNoDrawCanvas* DiscardableImageStore::GetNoDrawCanvas() { | 83 SkNoDrawCanvas* DiscardableImageStore::GetNoDrawCanvas() { |
83 return canvas_.get(); | 84 return canvas_.get(); |
84 } | 85 } |
85 | 86 |
86 void DiscardableImageStore::GatherDiscardableImages( | 87 void DiscardableImageStore::GatherDiscardableImages( |
87 const PaintOpBuffer* buffer) { | 88 const PaintOpBuffer* buffer) { |
88 if (!buffer->HasDiscardableImages()) | 89 if (!buffer->HasDiscardableImages()) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // embedded in SkPaints. Other embedded image cases, such as SkPictures, | 176 // embedded in SkPaints. Other embedded image cases, such as SkPictures, |
176 // are not yet handled. | 177 // are not yet handled. |
177 void DiscardableImageStore::AddImageFromFlags(const SkRect& rect, | 178 void DiscardableImageStore::AddImageFromFlags(const SkRect& rect, |
178 const PaintFlags& flags) { | 179 const PaintFlags& flags) { |
179 SkShader* shader = flags.getShader(); | 180 SkShader* shader = flags.getShader(); |
180 if (shader) { | 181 if (shader) { |
181 SkMatrix matrix; | 182 SkMatrix matrix; |
182 SkShader::TileMode xy[2]; | 183 SkShader::TileMode xy[2]; |
183 SkImage* image = shader->isAImage(&matrix, xy); | 184 SkImage* image = shader->isAImage(&matrix, xy); |
184 if (image) { | 185 if (image) { |
185 PaintImage paint_image(sk_ref_sp(image), | 186 PaintImage paint_image(unknown_stable_id_, sk_ref_sp(image), |
186 PaintImage::AnimationType::UNKNOWN, | 187 PaintImage::AnimationType::UNKNOWN, |
187 PaintImage::CompletionState::UNKNOWN); | 188 PaintImage::CompletionState::UNKNOWN); |
188 // TODO(ericrk): Handle cases where we only need a sub-rect from the | 189 // TODO(ericrk): Handle cases where we only need a sub-rect from the |
189 // image. crbug.com/671821 | 190 // image. crbug.com/671821 |
190 AddImage(paint_image, SkRect::MakeFromIRect(image->bounds()), rect, | 191 AddImage(paint_image, SkRect::MakeFromIRect(image->bounds()), rect, |
191 &matrix, flags); | 192 &matrix, flags); |
192 } | 193 } |
193 } | 194 } |
194 } | 195 } |
195 | 196 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 246 |
246 // TODO(khushalsagar): Keep PaintImage in DrawImage. | 247 // TODO(khushalsagar): Keep PaintImage in DrawImage. |
247 (*image_id_to_rect_)[sk_image->uniqueID()].Union(image_rect); | 248 (*image_id_to_rect_)[sk_image->uniqueID()].Union(image_rect); |
248 image_set_->push_back( | 249 image_set_->push_back( |
249 std::make_pair(DrawImage(std::move(sk_image), src_irect, filter_quality, | 250 std::make_pair(DrawImage(std::move(sk_image), src_irect, filter_quality, |
250 matrix, target_color_space), | 251 matrix, target_color_space), |
251 image_rect)); | 252 image_rect)); |
252 } | 253 } |
253 | 254 |
254 } // namespace cc | 255 } // namespace cc |
OLD | NEW |