| 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 #ifndef CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ | 5 #ifndef CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ |
| 6 #define CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ | 6 #define CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ |
| 7 | 7 |
| 8 #include <unordered_map> | |
| 9 #include <utility> | 8 #include <utility> |
| 10 #include <vector> | 9 #include <vector> |
| 11 | 10 |
| 12 #include "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" |
| 13 #include "cc/base/region.h" | |
| 14 #include "cc/base/rtree.h" | 12 #include "cc/base/rtree.h" |
| 15 #include "cc/playback/draw_image.h" | 13 #include "cc/playback/draw_image.h" |
| 16 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
| 17 #include "third_party/skia/include/core/SkRefCnt.h" | 15 #include "third_party/skia/include/core/SkRefCnt.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
| 20 | 18 |
| 21 namespace cc { | 19 namespace cc { |
| 22 | 20 |
| 23 // Helper function to apply the matrix to the rect and return the result. | 21 // Helper function to apply the matrix to the rect and return the result. |
| 24 SkRect MapRect(const SkMatrix& matrix, const SkRect& src); | 22 SkRect MapRect(const SkMatrix& matrix, const SkRect& src); |
| 25 | 23 |
| 26 // This class is used for generating discardable images data (see DrawImage | 24 // This class is used for generating discardable images data (see DrawImage |
| 27 // for the type of data it stores). It allows the client to query a particular | 25 // for the type of data it stores). It allows the client to query a particular |
| 28 // rect and get back a list of DrawImages in that rect. | 26 // rect and get back a list of DrawImages in that rect. |
| 29 class CC_EXPORT DiscardableImageMap { | 27 class CC_EXPORT DiscardableImageMap { |
| 30 public: | 28 public: |
| 31 // A map of SkImage id to the region for this image. | |
| 32 using ImageToRegionMap = std::unordered_map<uint32_t, Region>; | |
| 33 | |
| 34 class CC_EXPORT ScopedMetadataGenerator { | 29 class CC_EXPORT ScopedMetadataGenerator { |
| 35 public: | 30 public: |
| 36 ScopedMetadataGenerator(DiscardableImageMap* image_map, | 31 ScopedMetadataGenerator(DiscardableImageMap* image_map, |
| 37 const gfx::Size& bounds); | 32 const gfx::Size& bounds); |
| 38 ~ScopedMetadataGenerator(); | 33 ~ScopedMetadataGenerator(); |
| 39 | 34 |
| 40 SkCanvas* canvas() { return metadata_canvas_.get(); } | 35 SkCanvas* canvas() { return metadata_canvas_.get(); } |
| 41 | 36 |
| 42 private: | 37 private: |
| 43 DiscardableImageMap* image_map_; | 38 DiscardableImageMap* image_map_; |
| 44 std::unique_ptr<SkCanvas> metadata_canvas_; | 39 std::unique_ptr<SkCanvas> metadata_canvas_; |
| 45 }; | 40 }; |
| 46 | 41 |
| 47 DiscardableImageMap(); | 42 DiscardableImageMap(); |
| 48 ~DiscardableImageMap(); | 43 ~DiscardableImageMap(); |
| 49 | 44 |
| 50 bool empty() const { return all_images_.empty(); } | 45 bool empty() const { return all_images_.empty(); } |
| 51 void GetDiscardableImagesInRect(const gfx::Rect& rect, | 46 void GetDiscardableImagesInRect(const gfx::Rect& rect, |
| 52 const gfx::SizeF& raster_scales, | 47 const gfx::SizeF& raster_scales, |
| 53 std::vector<DrawImage>* images) const; | 48 std::vector<DrawImage>* images) const; |
| 54 Region GetRegionForImage(uint32_t image_id) const; | |
| 55 | 49 |
| 56 private: | 50 private: |
| 57 friend class ScopedMetadataGenerator; | 51 friend class ScopedMetadataGenerator; |
| 58 friend class DiscardableImageMapTest; | 52 friend class DiscardableImageMapTest; |
| 59 | 53 |
| 60 std::unique_ptr<SkCanvas> BeginGeneratingMetadata(const gfx::Size& bounds); | 54 std::unique_ptr<SkCanvas> BeginGeneratingMetadata(const gfx::Size& bounds); |
| 61 void EndGeneratingMetadata(); | 55 void EndGeneratingMetadata(); |
| 62 | 56 |
| 63 std::vector<std::pair<DrawImage, gfx::Rect>> all_images_; | 57 std::vector<std::pair<DrawImage, gfx::Rect>> all_images_; |
| 64 ImageToRegionMap image_id_to_region_; | |
| 65 | |
| 66 RTree images_rtree_; | 58 RTree images_rtree_; |
| 67 }; | 59 }; |
| 68 | 60 |
| 69 } // namespace cc | 61 } // namespace cc |
| 70 | 62 |
| 71 #endif // CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ | 63 #endif // CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ |
| OLD | NEW |