| 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/paint/discardable_image_map.h" | 5 #include "cc/paint/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/containers/flat_map.h" |
| 13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 14 #include "cc/base/math_util.h" | 15 #include "cc/base/math_util.h" |
| 15 #include "cc/paint/display_item_list.h" | 16 #include "cc/paint/display_item_list.h" |
| 16 #include "third_party/skia/include/core/SkPath.h" | 17 #include "third_party/skia/include/core/SkPath.h" |
| 17 #include "third_party/skia/include/utils/SkNWayCanvas.h" | 18 #include "third_party/skia/include/utils/SkNWayCanvas.h" |
| 18 #include "ui/gfx/geometry/rect_conversions.h" | 19 #include "ui/gfx/geometry/rect_conversions.h" |
| 19 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
| 20 | 21 |
| 21 namespace cc { | 22 namespace cc { |
| 22 | 23 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 namespace { | 57 namespace { |
| 57 | 58 |
| 58 // We're using an NWay canvas with no added canvases, so in effect | 59 // We're using an NWay canvas with no added canvases, so in effect |
| 59 // non-overridden functions are no-ops. | 60 // non-overridden functions are no-ops. |
| 60 class DiscardableImagesMetadataCanvas : public SkNWayCanvas { | 61 class DiscardableImagesMetadataCanvas : public SkNWayCanvas { |
| 61 public: | 62 public: |
| 62 DiscardableImagesMetadataCanvas( | 63 DiscardableImagesMetadataCanvas( |
| 63 int width, | 64 int width, |
| 64 int height, | 65 int height, |
| 65 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set, | 66 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set, |
| 66 std::unordered_map<ImageId, gfx::Rect>* image_id_to_rect) | 67 base::flat_map<ImageId, gfx::Rect>* image_id_to_rect) |
| 67 : SkNWayCanvas(width, height), | 68 : SkNWayCanvas(width, height), |
| 68 image_set_(image_set), | 69 image_set_(image_set), |
| 69 image_id_to_rect_(image_id_to_rect), | 70 image_id_to_rect_(image_id_to_rect), |
| 70 canvas_bounds_(SkRect::MakeIWH(width, height)), | 71 canvas_bounds_(SkRect::MakeIWH(width, height)), |
| 71 canvas_size_(width, height) {} | 72 canvas_size_(width, height) {} |
| 72 | 73 |
| 73 protected: | 74 protected: |
| 74 // we need to "undo" the behavior of SkNWayCanvas, which will try to forward | 75 // we need to "undo" the behavior of SkNWayCanvas, which will try to forward |
| 75 // it. | 76 // it. |
| 76 void onDrawPicture(const SkPicture* picture, | 77 void onDrawPicture(const SkPicture* picture, |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 matrix.postConcat(ctm); | 241 matrix.postConcat(ctm); |
| 241 // TODO(ericrk): Handle cases where we only need a sub-rect from the | 242 // TODO(ericrk): Handle cases where we only need a sub-rect from the |
| 242 // image. crbug.com/671821 | 243 // image. crbug.com/671821 |
| 243 AddImage(sk_ref_sp(image), SkRect::MakeFromIRect(image->bounds()), | 244 AddImage(sk_ref_sp(image), SkRect::MakeFromIRect(image->bounds()), |
| 244 MapRect(ctm, rect), matrix, &paint); | 245 MapRect(ctm, rect), matrix, &paint); |
| 245 } | 246 } |
| 246 } | 247 } |
| 247 } | 248 } |
| 248 | 249 |
| 249 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set_; | 250 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set_; |
| 250 std::unordered_map<ImageId, gfx::Rect>* image_id_to_rect_; | 251 base::flat_map<ImageId, gfx::Rect>* image_id_to_rect_; |
| 251 const SkRect canvas_bounds_; | 252 const SkRect canvas_bounds_; |
| 252 const gfx::Size canvas_size_; | 253 const gfx::Size canvas_size_; |
| 253 std::vector<SkPaint> saved_paints_; | 254 std::vector<SkPaint> saved_paints_; |
| 254 }; | 255 }; |
| 255 | 256 |
| 256 } // namespace | 257 } // namespace |
| 257 | 258 |
| 258 DiscardableImageMap::DiscardableImageMap() {} | 259 DiscardableImageMap::DiscardableImageMap() {} |
| 259 | 260 |
| 260 DiscardableImageMap::~DiscardableImageMap() {} | 261 DiscardableImageMap::~DiscardableImageMap() {} |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 DiscardableImageMap* image_map, | 297 DiscardableImageMap* image_map, |
| 297 const gfx::Size& bounds) | 298 const gfx::Size& bounds) |
| 298 : image_map_(image_map), | 299 : image_map_(image_map), |
| 299 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} | 300 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} |
| 300 | 301 |
| 301 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { | 302 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { |
| 302 image_map_->EndGeneratingMetadata(); | 303 image_map_->EndGeneratingMetadata(); |
| 303 } | 304 } |
| 304 | 305 |
| 305 } // namespace cc | 306 } // namespace cc |
| OLD | NEW |