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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 } | 65 } |
66 | 66 |
67 private: | 67 private: |
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<PaintImage::Id, 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()) {} | |
80 | 79 |
81 DiscardableImageStore::~DiscardableImageStore() = default; | 80 DiscardableImageStore::~DiscardableImageStore() = default; |
82 | 81 |
83 SkNoDrawCanvas* DiscardableImageStore::GetNoDrawCanvas() { | 82 SkNoDrawCanvas* DiscardableImageStore::GetNoDrawCanvas() { |
84 return canvas_.get(); | 83 return canvas_.get(); |
85 } | 84 } |
86 | 85 |
87 void DiscardableImageStore::GatherDiscardableImages( | 86 void DiscardableImageStore::GatherDiscardableImages( |
88 const PaintOpBuffer* buffer) { | 87 const PaintOpBuffer* buffer) { |
89 if (!buffer->HasDiscardableImages()) | 88 if (!buffer->HasDiscardableImages()) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 // embedded in SkPaints. Other embedded image cases, such as SkPictures, | 175 // embedded in SkPaints. Other embedded image cases, such as SkPictures, |
177 // are not yet handled. | 176 // are not yet handled. |
178 void DiscardableImageStore::AddImageFromFlags(const SkRect& rect, | 177 void DiscardableImageStore::AddImageFromFlags(const SkRect& rect, |
179 const PaintFlags& flags) { | 178 const PaintFlags& flags) { |
180 SkShader* shader = flags.getShader(); | 179 SkShader* shader = flags.getShader(); |
181 if (shader) { | 180 if (shader) { |
182 SkMatrix matrix; | 181 SkMatrix matrix; |
183 SkShader::TileMode xy[2]; | 182 SkShader::TileMode xy[2]; |
184 SkImage* image = shader->isAImage(&matrix, xy); | 183 SkImage* image = shader->isAImage(&matrix, xy); |
185 if (image) { | 184 if (image) { |
186 PaintImage paint_image(unknown_stable_id_, sk_ref_sp(image), | 185 // We currently use the wrong id for images that come from shaders. We |
186 // don't know what the stable id is, but since the completion and | |
187 // animation states are both unknown, this value doesn't matter as it | |
188 // won't be used in checker imaging anyway. Keep this value the same to | |
189 // avoid id churn. | |
190 // TODO(vmpstr): Remove this when we can add paint images into shaders | |
191 // directly. | |
192 PaintImage paint_image(PaintImage::kWrongStableId, sk_ref_sp(image), | |
vmpstr
2017/05/16 17:43:27
Maybe call it kUnknownStableId? If it's wrong, the
Khushal
2017/05/16 21:29:12
Done.
I thought calling it wrong will give me a pu
| |
187 PaintImage::AnimationType::UNKNOWN, | 193 PaintImage::AnimationType::UNKNOWN, |
188 PaintImage::CompletionState::UNKNOWN); | 194 PaintImage::CompletionState::UNKNOWN); |
189 // TODO(ericrk): Handle cases where we only need a sub-rect from the | 195 // TODO(ericrk): Handle cases where we only need a sub-rect from the |
190 // image. crbug.com/671821 | 196 // image. crbug.com/671821 |
191 AddImage(paint_image, SkRect::MakeFromIRect(image->bounds()), rect, | 197 AddImage(std::move(paint_image), SkRect::MakeFromIRect(image->bounds()), |
192 &matrix, flags); | 198 rect, &matrix, flags); |
193 } | 199 } |
194 } | 200 } |
195 } | 201 } |
196 | 202 |
197 void DiscardableImageStore::AddImage(const PaintImage& paint_image, | 203 void DiscardableImageStore::AddImage(PaintImage paint_image, |
198 const SkRect& src_rect, | 204 const SkRect& src_rect, |
199 const SkRect& rect, | 205 const SkRect& rect, |
200 const SkMatrix* local_matrix, | 206 const SkMatrix* local_matrix, |
201 const PaintFlags& flags) { | 207 const PaintFlags& flags) { |
202 sk_sp<const SkImage> sk_image = paint_image.sk_image(); | 208 if (!paint_image.sk_image()->isLazyGenerated()) |
203 if (!sk_image->isLazyGenerated()) | |
204 return; | 209 return; |
205 | 210 |
206 const SkRect& clip_rect = SkRect::Make(canvas_->getDeviceClipBounds()); | 211 const SkRect& clip_rect = SkRect::Make(canvas_->getDeviceClipBounds()); |
207 const SkMatrix& ctm = canvas_->getTotalMatrix(); | 212 const SkMatrix& ctm = canvas_->getTotalMatrix(); |
208 | 213 |
209 SkRect paint_rect = MapRect(ctm, rect); | 214 SkRect paint_rect = MapRect(ctm, rect); |
210 bool computed_paint_bounds = | 215 bool computed_paint_bounds = |
211 canvas_->ComputePaintBounds(paint_rect, ToSkPaint(&flags), &paint_rect); | 216 canvas_->ComputePaintBounds(paint_rect, ToSkPaint(&flags), &paint_rect); |
212 if (!computed_paint_bounds) { | 217 if (!computed_paint_bounds) { |
213 // TODO(vmpstr): UMA this case. | 218 // TODO(vmpstr): UMA this case. |
(...skipping 23 matching lines...) Expand all Loading... | |
237 image_rect.Inset(-1, -1); | 242 image_rect.Inset(-1, -1); |
238 | 243 |
239 // The true target color space will be assigned when it is known, in | 244 // The true target color space will be assigned when it is known, in |
240 // GetDiscardableImagesInRect. | 245 // GetDiscardableImagesInRect. |
241 gfx::ColorSpace target_color_space; | 246 gfx::ColorSpace target_color_space; |
242 | 247 |
243 SkMatrix matrix = ctm; | 248 SkMatrix matrix = ctm; |
244 if (local_matrix) | 249 if (local_matrix) |
245 matrix.postConcat(*local_matrix); | 250 matrix.postConcat(*local_matrix); |
246 | 251 |
247 // TODO(khushalsagar): Keep PaintImage in DrawImage. | 252 (*image_id_to_rect_)[paint_image.stable_id()].Union(image_rect); |
vmpstr
2017/05/16 17:43:27
I don't think it is, but is it possible for us to
Khushal
2017/05/16 21:29:12
It shouldn't be. The uniqueID essentially represen
| |
248 (*image_id_to_rect_)[sk_image->uniqueID()].Union(image_rect); | |
249 image_set_->push_back( | 253 image_set_->push_back( |
250 std::make_pair(DrawImage(std::move(sk_image), src_irect, filter_quality, | 254 std::make_pair(DrawImage(std::move(paint_image), src_irect, |
251 matrix, target_color_space), | 255 filter_quality, matrix, target_color_space), |
252 image_rect)); | 256 image_rect)); |
253 } | 257 } |
254 | 258 |
255 } // namespace cc | 259 } // namespace cc |
OLD | NEW |